我有如下一段代码
setTimeout(()=>{ console.log("TIMED OUT DATA", this.fetchedData['__zone_symbol__value']) },3000);
我想在 setTimeout 之外获取 this.fetchedData['__zone_symbol__value']
的值。有可能吗?
最佳答案
只需在外部声明并直接引用即可。
赞here, in this working example .
export class App {
myData = false;
constructor() {
this.restart();
}
restart(){
console.log("Changind data to false outside timeout");
this.myData = false;
setTimeout(()=>{
console.log("TIMED OUT DATA", this.myData)
this.myData = true;
console.log("TIMED OUT DATA changed", this.myData)
},3000);
}
}
关于angular - 如何获取在其外部 "SetTimeout"内部生成的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49666039/