[英]Javascript/Angular: timeout wrapped in function not workink with boolean value
In the View I have this condition: 在视图中,我有这种情况:
<h3 *ngIf="show">{{users.result}}</h3>
In the TypeScript logic I have: 在TypeScript逻辑中,我有:
show=false; <----as a property
And the the following function: 和以下功能:
timeOut(seconds: number, value:boolean) {
value = true;
setTimeout(
function() {
value = false;
}.bind(this),
seconds
);
}
But when I call it, like this: 但是当我这样称呼它时:
console.log(this.timeOut(3000, this.show));
the property `this.show´ gets undefined, but the seconds passed as argument work. 属性“ this.show”未定义,但秒作为参数起作用了。 I'm missing something and I can't figure out what... Can anyone give a help?
我丢失了一些东西,我不知道该怎么办...有人可以帮忙吗?
As i see: 如我所见:
My suggestion - just put setTimeout call with arrow function into some component's method like ngAfterViewInit or in event handler method : 我的建议-只需将带有箭头功能的 setTimeout调用放到某些组件的方法(如ngAfterViewInit)中或事件处理程序方法中 :
ngAfterViewInit() {
setTimeout(() => this.show = true, 3000)
}
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.