【发布时间】:2020-02-07 21:18:36
【问题描述】:
试图在变量中分配事件但不起作用。我不知道如何分配。我进入 console.log(this.myEvents) 就像 null 一样,无法访问最近的 tr。如果有人知道,请帮助找到解决方案。
app.component.ts:
public myEvents:any;
logEvent(e)
{
this.myEvents=e; // Store event info
}
// Set a timer for looping through the events
gameTimer = setInterval(function() {
// Loop through events
if(this.myEvents)
{
console.log(this.myEvents);// getting null
}
}, 100)
app.component.html:
<button (click)="logEvent(e)">Set event</button>
演示:https://stackblitz.com/edit/angular-yqelod?file=src/app/app.component.ts
【问题讨论】:
-
有什么问题?
-
@VLAZ:如何将事件保存在变量中
-
但是你这里的代码有什么问题?什么不起作用?你有任何错误吗?你有意外的行为吗?你期望的行为是什么?说“不起作用”对于试图确定问题所在以及如何解决问题没有帮助。
-
@VLAZ:编辑了我的问题..我得到 this.myEvents 为空
标签: typescript angular6 angular7 angular8