How can I call ngOnChanges only after all input values ​​have been set to ngOnInit

How can I call ngOnChanges only after all input values ​​are set in ngOnInit. My code →

`ngOnInit() {
this.multiSelectorData.forEach(item=>{
            this.allItems.push(item.data);
        });
}
ngOnChanges(changes: SimpleChanges) {
        if(changes['dataReady'] && changes['dataReady'].currentValue) {
   console.log(this.allItems);
}`

I will not get the initialized array in ngonit in ngonchanges because ngonchanges is called before ngonit, how can I check if everything is initialized before the ngonchanges check?

+2
source share
1 answer

, , . , CD_INIT_VALUE ( ). , , ngOnChanges , CD_INIT_VALUE. , :

ngOnChanges(changes: SimpleChanges) {
  let initialized: boolean = true;
  for (let prop in changes) {
    if (changes[prop].previousValue.toString() === 'CD_INIT_VALUE') {
      initialized = false;
      //we can break here since if any item is not initialized
      //we will say the inputs are NOT initialized
      break;
    }
  }

  if (initialized) {
    //code you want to execute
  }    
}

, , , , . , , , , , , googled, . , .

0

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


All Articles