Angular2 View does not refresh when using setInterval

I am using Angular2 RC5 - and I have a strange problem. In my main component, I use for testing in my constructor:

 setInterval(() => {
        this.test = new Date().getMilliseconds().toString();           
    }, 500);

Binding in my template

<p>{{test}}</p>

When loading or reloading the page, it either displays the value (but does not change at subsequent ticks), sometimes it works as intended (updates the value at each tick), and sometimes it simply displays the initial value and does not change at all, It seems random.

I'm going crazy about this, because it seems that in the official version of the plunker it works without problems. (Edit: Link to the plunger )

I get the same behavior when using this code in other components.

Any idea?

+4
2

, .

import {Observable} 'rxjs/Observable';

Observable.interval(500)
    .subscribe(() => {
    this.test = new Date().getMilliseconds().toString();    
})
+1

, , ,

<script src="https://use.fontawesome.com/f0298bc7e9.js"></script>

index.html . , ... , . : . : .
: "" ...

0

Source: https://habr.com/ru/post/1651898/


All Articles