Momin Shahzad
Momin Shahzad

Reputation: 747

how to fix the change detection method in angular 8. How to achieve this immediately without manual writing detect changes every time

I have a project in angular 8, basically it's kind of a distribution system, each component run independently with its own server and services and then i am using that component as a plugin in my main application where several components are running independently as a plugin. so the issue is, when the component run independently, it works fine but when i used it as a plugin in main application , it is not detecting changes for events/clickable events. Every time i need to add ref.detectChanges() beneath the functions. How to achieve this immediately and change detection's without manually writing ref.detectChanges() after each model change ?. Any help will be highly appreciated. Thanks

  hideDropdown(){
    this.showDropdwn = !this.showDropdwn;
    this.cdRef.detectChanges();
  }

  getConfig() {
    this.frontofficeApiService.getConfig(this.tile.webApiRoot).subscribe(data => {
      this.bpsData = data.bps;
      this.qtyData = data.quantity;
      this.cd.detectChanges();
    })
  }

Upvotes: 0

Views: 382

Answers (1)

Sandeep Pal
Sandeep Pal

Reputation: 94

If the changes are getting reflected only after detectChanges() method of ChangeDetectorRef, then your component is detached from the change detection tree. Have to tried to call reattach method of ChangeDetectorRef in the ngOnInit method of the component?

Upvotes: 1

Related Questions