I have a problem with ngOnChange . I have the following component:
@Component({ selector:'user-table', template: `...`, }) export class UserTable implements OnChanges{ @Input() users: User[]; years:string[]; constructor(private _usersCollection:UsersCollection){ } ngOnChanges(){ if (this.users.length) {this.years =this._usersCollection.createYearsArray(this.users)} } }
However, if the condition is checked only once - when this.users has not yet been received from the server, and therefore its length is 0. How can I find a solution to work with such asynchronous inputs?
The array is updated when I install the following logs:
console.log('ON FIRST INIT' , this.programs); this.years = this._usersCollection.createYearsArray(); console.log(this.years); setInterval(()=>{ console.log('IN INTERVVAL' , this.programs); },1000);
Console output:
ON FIRST INIT [] UsersTable.component.ts:21 [] UsersTable.component.ts:23 IN INTERVVAL [Object, Object, Object, Object]
angular
uksz
source share