import {Component, EventEmitter, OnInit} from 'angular2/core';
import {Router, RouteData, RouteParams} from 'angular2/router';
import {Observable} from 'rxjs/Observable';
@Component({
selector: 'response',
templateUrl: 'app/templates/response.html'
})
export class ResponseComponent implements OnInit {
searchResult = {};
constructor(routeData: RouteData) {
this.searchResult = routeData.get('searchResult');
console.log(this.searchResult);
}
ngOnInit() {
console.log('in init');
console.log(this.searchResult);
}
}
我从父组件路由到此组件,但是this.searchResult没有设置为在模板中使用,也没有调用ngOnInit()方法。
我能够在构造函数中获取路径数据,并在控制台记录时进行打印。