Monday 16 July 2018

Angular 6 variable not resolved in Google Chrome (web component)

Using Angular 6 I created a web component that is integrated from another application. Everything works on all browsers when running without an integration. When the web component is integrated in an other application it works on IE, Safari, FF but not on Chrome.

I managed to identify the problem. The first call gets some configuration data from my backend. It's supposed to be written into the var this.conf, but that does not happen in Chrome when being integrated.

My component:

public conf: any;

ngOnInit() {
  this.getData();
  console.log('Conf ngOnInit:', this.conf);
}

getData() {
  return this.partnerService.getData(this.name)
    .subscribe(
      (partner: any) => {
        console.log('partner: ', partner);
        this.conf = {
          id: partner['id'],
          name: partner['name']
        }
        console.log('conf:', this.conf);
     )
}

Partner Service:

@Injectable()
export class PartnerService {

  constructor(public http: HttpClient) {
  }

  getData(name: string) {
    return this.http.get(environment.apiUrl + 'partners/conf/' + name)
      .map(resp => resp['partner']);
  }
}

My view:

<pre>Conf: </pre>

Console output:

Conf ngOnInit: undefined
partner: {id: 1, name: "xxx", booking_name: "xxx", …}
conf: {id: 1, name: "xxx"}

The var did not get resolved in the view. What could this be?



from Angular 6 variable not resolved in Google Chrome (web component)

No comments:

Post a Comment