Skip to content Skip to sidebar Skip to footer

AngularJS 2 EXCEPTION: Error: Uncaught (in Promise): TypeError: Cannot Set Property 'company' Of Null

I stuck for all day and don't know why. This is the code of component: import {Component, ViewEncapsulation, OnInit} from '@angular/core'; import {ROUTER_DIRECTIVES} from '@angular

Solution 1:

You should use an arrow function to be able to use the lexical this in the callback:

getCompany(){
  this.companyService.getCompany().then((company) => {
    console.log(company);
    this.company = company;
    }
  );
}

Post a Comment for "AngularJS 2 EXCEPTION: Error: Uncaught (in Promise): TypeError: Cannot Set Property 'company' Of Null"