This problem should be quite simple: I want to push the status of each query into an array called currentValues. Unfortunately, the currentValues-array remains unpopulated (the output of check values is 0vs2. What am I 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() {
for ( 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 i = 0;
let allSatisfied: boolean;
for ( 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 });
}