I could not make it persistent behavior in HTML part while using subscribe to the http client in the Anglar 9. I tried following stackoverflow posts -
- Angular 2 View will not update after variable change in subscribe
- Angular 6 View is not updated after changing a variable within subscribe
Following is the code what I am trying
export class BaseComponent implements OnInit, OnDestroy {
list: any[];
unsubscribe$: Subject<any> = new Subject();
constructor(private ngZone: NgZone,private changeRef: ChangeDetectorRef) {
}
ngOnInit(): void {
return this.http
.get(environment.apiBaseUrl + url, this.getOptions())
.pipe(takeUntil(this.unsubscribe$))
.subscribe(()=>{
this.ngZone.run(()=>{
this.list = response.data;
})
this.list = response.data;
this.changeRef.detectChanges();
this.changeRef.markForCheck();
});
}
ngOnDestroy(): void {
this.unsubscribe$.next();
this.unsubscribe$.complete();
}
}
// Nothing working for me.