angular - Array push is not working correctly -


this problem should quite simple: want push status of each query array called currentvalues. unfortunately, currentvalues-array remains unpopulated (the output of check values 0vs2. missing here?

 @input() public wantedvalue: string[];   @input() public querysensor: string[];   @input() public slideid:  number;   @output() wantedstateaccievedevent: eventemitter<any> = new eventemitter<any>();   public currentvalues: string[] = [];    inititems() {     ( let sensor of this.querysensor ) {       console.log("sensor: " + sensor);       this.itemservice.getmockitemstate(sensor).subscribe(         status => { this.currentvalues.push((status)); });     }     this.checkvalues();   }    checkvalues(): void {     console.log("called checkvalues" + this.currentvalues.length + "vs " + this.wantedvalue.length);     let = 0;     let allsatisfied: boolean;     ( let value of this.currentvalues) {       console.log("wert: " + value + '\n');       if ( this.wantedvalue[i] !== value ) {         allsatisfied = false;       }       i++;     }     if ( allsatisfied === true ) {       this.wantedstateaccievedevent.emit({slideid: this.slideid, stateaccieved: true });     } 

you're subscribing asynchronous event this.itemservice.getmockitemstate(sensor).subscribe. it's possible when call this.checkvalues() event wasn't triggered already.

try postpone this.checkvalues() fill seconds or move call inside subscribe function:

this.itemservice.getmockitemstate(sensor)   .subscribe(status => {     this.currentvalues.push(status);     this.checkvalues();   }); 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -