Questions tagged «ngoninit»



3
Angular2的ngOnInit和ngAfterViewInit有什么区别?
我无法理解ngOnInit和之间的区别ngAfterViewInit。 我发现它们之间的唯一区别是@ViewChild。根据以下代码,elementRef.nativeElement它们中的是相同的。 我们应该使用什么场景ngAfterViewInit? @Component({ selector: 'my-child-view', template: ` <div id="my-child-view-id">{{hero}}</div> ` }) export class ChildViewComponent { @Input() hero: string = 'Jack'; } ////////////////////// @Component({ selector: 'after-view', template: ` <div id="after-view-id">-- child view begins --</div> <my-child-view [hero]="heroName"></my-child-view> <div>-- child view ends --</div>` + ` <p *ngIf="comment" class="comment"> {{comment}} </p> ` }) …
78 angular  ngoninit 
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.