我的ngOndestroy正在调用其他路由导航,但它没有在方法中执行clearInterval.我哪里弄错了?它在后台运行,而我在其他组件中.
timer:any;
ngOnInit() {
this.timer= this.interval();
};
ngOnDestroy(){
clearInterval(this.timer);
console.log("Inside Destroy");
}
interval(){
setInterval(()=>{
this.getData();
},20000)
}
getData(){
this.dataservice.getdata()
.subscribe(users=>{
this.datas=users;
console.log(this.datas);
})
}
Run Code Online (Sandbox Code Playgroud) 每当我在视图模板中尝试类似的操作时,它都会按预期工作。
{{20*30}}
但每当我尝试
{{somevalue1*somevalue2}}
其中somevalue1
和somevalue2
两者都来自组件并且somevalue2
来自 api 并且它位于数组内,它显示 NaN。
该怎么处理呢?
是因为 String 值吗?
如何将其转换为模板中的数字?