我有以下代码:
class TreeComponent {
entity: any;
constructor(private $rootScope: ng.IScope) {
console.log(this.entity);
}
}
AppModule.component('tree', {
templateUrl: '<tree entity="obj"></tree>',
controller: ['$rootScope', TreeComponent],
bindings: {
entity: '='
}
})
我希望console.log(this.entity)打印插入'tree'标签的obj。我不知道为什么,但它打印'undefined'。你知道为什么吗?
答案 0 :(得分:0)
最后,我发现'entity'属性仅在离开构造函数后绑定到对象。例如,
class TreeComponent {
entity: any;
constructor(private $rootScope: ng.IScope) {
console.log(this.entity);
}
debug() {
console.log(this.entity);// it works
}
}