[英]Javascript/Angular: timeout wrapped in function not workink with boolean value
在視圖中,我有這種情況:
<h3 *ngIf="show">{{users.result}}</h3>
在TypeScript邏輯中,我有:
show=false; <----as a property
和以下功能:
timeOut(seconds: number, value:boolean) {
value = true;
setTimeout(
function() {
value = false;
}.bind(this),
seconds
);
}
但是當我這樣稱呼它時:
console.log(this.timeOut(3000, this.show));
屬性“ this.show”未定義,但秒作為參數起作用了。 我丟失了一些東西,我不知道該怎么辦...有人可以幫忙嗎?
如我所見:
我的建議-只需將帶有箭頭功能的 setTimeout調用放到某些組件的方法(如ngAfterViewInit)中或事件處理程序方法中 :
ngAfterViewInit() {
setTimeout(() => this.show = true, 3000)
}
希望能有所幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.