What is best practice and where is the difference between:
export class suchPage {
@ViewChild(SuchDirective) suchDirective:SuchDirective;
}
and
export class suchPage {
@ViewChild(SuchDirective);
constructor(
private suchDirective:SuchDirective
) {}
}
Official documentation references the first method. I'm guessing it's the best practice:
https://angular.io/docs/ts/latest/cookbook/component-communication.html#!#parent-to-view-child
第二种方法不起作用,因为ViewChild
注入的元素仅在视图初始化( ngAfterViewInit
)之后可用。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.