I'm new to Angular 2 and I'm building an app. I want to update the variable value on view with setInterval()
function. The function is executed but the view is not geting updated with the value of 'title' which updates every second:
public title: number;
public t = setInterval(this.test, 1000);
test() {
var i: number = Math.random();
this.title = i;
console.log(i);
}
This code does not update the view. But after changing to this code, it works:
public title: number;
public t = setInterval(() => { this.test(); }, 1000);
test() {
var i: number = Math.random();
this.title = i;
console.log(i);
}
The console.log(i) prints correct values in both cases everytime its called. When checked using Chrome debugger, the value of 'this.title' is getting updated by 'i'. Its just that the value is not getting updated in View.