我有一個組件,我想從模板中訪問一些子節點。我達到了訪問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()',並嘗試''新'未來...'後打印(詳細)'' –