How can a variable always be checked?


Hello i am loolinhg for a solution for that ;

I have integer variable and i always want to check it weather it is zero or not ?
like subscribe it !

BUT how can i do this

Thanks in Advance


Where do you want to do this? If “from a template”, then just let Angular’s change detection deal with it:

<div *ngIf="!foo">foo is zero</div>


what about at ts file ? it s like kind of a state controll but basic just one variable


Check it in your constructor for example, eg, if this.myvalue != “null || undefined” { this.myvalue = something }.


You can check that variable within your ts file.

import {Observable } from 'rxjs/Rx';
    Observable.interval(100).subscribe(x => {
        if(variable == 0)
            //do this
        {   //do that 


However this checks only once ! it need to be like state controller .


@techsnake you’re right, then work with @amitk04 answer just above :slight_smile: (an observable or promise)


Please describe what you are actually trying to achieve. Periodically polling like the suggestion given above involving interval is a wasteful use of resources.