我有一个组件,我想从模板中访问一些子节点。我达到了访问details
股利,但我不知道为什么代码的作品。 Future class
究竟是什么?为什么第一行输出为空?这是从模板访问子节点的正确方法吗?Angular2:从模板访问子节点
@Component(selector: 'hero-detail', template: '<div #details></div>')
class HeroDetailComponent implements OnInit {
Hero hero;
@ViewChild('details')
var details;
Future ngOnInit() async {
// why this command prints null?
print(details);
// why this command prints "Instance of 'ElementRef_'"
new Future(() => print(details));
}
}
我不知道,但镖似乎是几个错误1.'英雄好汉;'应该是'英雄:英雄;在angular2'2.我们不能给名字的生命周期挂钩喜欢你'未来的ngOnInit()',并尝试''新'未来...'后打印(详细)'' –