Я пытаюсь понять, как лучше подождать, пока шаблон обновится в приложении Angular 2 после изменения модели.Как правильно дождаться обновления шаблона в Angular 2
@Component{
template : `<button type="button" (click)="handleClick()">Click</button>
<div *ngIf="!hidden">
<input type='text' #eleInput/>
</div>`
}
export class Sample{
private hidden: boolean = true;
@ViewChild('eleInput') eleInput: ElementRef;
constructor(){}
handleClick(){
this.hidden = false;
//nativeElement is undefined here
this.eleInput.nativeElement.focus();
//nativeElement is defined here
setTimeout(() => {
this.eleInput.nativeElement.focus();
});
}
}
Использование SetTimeout в приведенном выше коде кажется Hacky, поэтому я хотел бы знать, если есть лучший подход.
Спасибо!
Посмотрите на [Анимации] (https://angular.io/docs/ts/latest/guide/animations.html#!#example-entering-and-leaving) .. – Sasxa