* ng가 템플릿을 업데이트하지 않는 이유는 무엇입니까? hello라는 제목은 2 초 후에 isVisible이 false로 변경된다는 사실과 관계없이 항상 표시됩니다. 이 하나각도 2 * ng HTML 템플릿을 업데이트하지 않는 경우
setTimeout(function() {
this.isVisible = false;
}, 2000);
실행 컨텍스트 (this
)와 같은 익명 함수와
@Component({
selector: 'my-app',
template: `
<h1 *ngIf="isVisible == true">{{title}}</h1>
`
})
export class AppComponent {
title = 'Hello!';
isVisible = true;
constructor() {
setTimeout(function() {
this.isVisible = false;
console.log(this.isVisible);
}, 2000);
}
}