我正在使用Angular2。我有一个div:setTimeOut for elementRef
<div class="saved" #saved>
<p>Saved</p>
<i class="fa fa-check" aria-hidden="true"></i>
</div>
我访问它在TS:
@ViewChild("saved") public saved: ElementRef;
接下来我显示该块:
this.saved.nativeElement.style.display = 'block';
然后,我想几秒钟后隐藏它,但是这部分代码不正确:
setTimeout(this.closeSavedWindow, 3000);
其中
closeSavedWindow() {
this.saved.nativeElement.style.display = 'none';
}
的错误是
TypeError: this.saved is undefined
这有内部和外部的功能,两个不同的上下文可以调试此使用的console.log(本) closeSavedWindoe() –