只要服務器註冊新的調用者,我就得到了此代碼,它將調用者添加到數組中。在Angular/Typescript中刪除/拼接數組中的元素
caller = new CallerData;
callers = new Array<CallerData>();
ngOnInit() {
this.callService.exposeCallerObservable().subscribe(
(x: CallerData) => {
this.caller = x;
this.callers.push(x);
},
(error: any) => {
console.warn("Could not subscribe to the Caller Observable!", error);
}
)
}
現在我想保持每個調用者只有5-10秒的數組,並在這段時間後,它應該再次被刪除。你能幫助我嗎?
後'this.callers.push(X);'可以寫像'的setTimeout(()=> {this.callers = [];} ,5000)' – echonax
完美!感謝這就是我一直在尋找:) – reveN
我會提供它作爲一個答案,然後:-) – echonax