AfterViewChecked

export interface AfterViewChecked

exported from angular2/core defined in angular2/src/core/linker/interfaces.ts (line 428)

Implement this interface to get notified after every check of your component's view.

Example (live demo)

@Component({selector: 'child-cmp', template: `{{where}} child`}) class ChildComponent { @Input() where: string; } @Component({ selector: 'parent-cmp', template: ` <button (click)="showView = !showView">Toggle view child</button> <child-cmp *ngIf="showView" where="view"></child-cmp>`, directives: [NgIf, ChildComponent] }) class ParentComponent implements AfterViewChecked { @ViewChild(ChildComponent) viewChild: ChildComponent; showView = true; constructor() { // viewChild is not initialized yet console.log(this.getMessage(this.viewChild)); } ngAfterViewChecked() { // viewChild is updated after the view has been checked console.log('AfterViewChecked: ' + this.getMessage(this.viewChild)); } private getMessage(cmp: ChildComponent): string { return cmp ? cmp.where + ' child' : 'no child'; } } @Component({ selector: 'app', template: `<parent-cmp></parent-cmp>`, directives: [ParentComponent] }) export class App { } bootstrap(App).catch(err => console.error(err));

Members

ngAfterViewChecked()

Not Yet Documented