Home > Mobile >  In angular when i click in anywhere data will be display so can u find the error
In angular when i click in anywhere data will be display so can u find the error

Time:03-05

ngOnInit() {
    this.getPosts()
      .subscribe((config: any) => {
        this.data = Object.values(config);
        this.config=this.data[0];    })}
  getPosts() {
   
    return this.http.post<any>(this.postsUrl, raw
      , { 'headers': headers });}

In angular i used this method and used ngfor, and it will print data after any click ! help me

  <nb-option *ngFor="let vehicle of config" [value]="vehicle.REGIS_NO">
{{ vehicle.REGIS_NO }}
</nb-option>

CodePudding user response:

add detectors to detact any change after component load.

constructor(private cd : ChangeDetectorRef ) { }

Add this.cd.markForCheck() after subscribe

.subscribe((config: any) => {
    this.cd.markForCheck()
    this.data = Object.values(config);
  • Related