title: AngularJS 2 EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot set property 'company' of null
body: <p>I stuck for all day and don't know why. This is the code of component:</p>
  
  <pre><code>import {Component, ViewEncapsulation, OnInit} from '@angular/core';
  import {ROUTER_DIRECTIVES} from '@angular/router-deprecated';
  import {Company} from './company';
  import {Job} from './job'
  import {CompanyService} from './company-service';
  
  @Component({
    directives: [
    ROUTER_DIRECTIVES,
    ],
    selector: '[job-list-page]',
    host: {
      class: 'job-list-page app'
    },
    template: require('./job-list-page.html'),
    encapsulation: ViewEncapsulation.None,
    styles: [require('./job-list-page.scss'), require('./login-page.scss')],
    providers: [CompanyService]
  })
  
  
  export class JobListPage implements OnInit{
    company: Company;
    constructor(private companyService: CompanyService){}
  
    ngOnInit(){
      this.getCompany();
    }
  
    getCompany(){
      this.companyService.getCompany().then(function(company){
        console.log(company);
        this.company = company;
        }
      );
    }
  }
  </code></pre>
  
  <p>This is the code of company-service.ts:</p>
  
  <pre><code>import { Injectable } from '@angular/core';
  import { Company } from './company';
  import { Job } from './job'
  import { COMPANY } from './mock-company';
  
  @Injectable()
  export class CompanyService{
      getCompany(){
          return Promise.resolve(COMPANY);
      }
  }
  </code></pre>
  
  <p>I got the object in the getCompany(). But I can't assign the object to the this.company. It will show the error. I don't know why. It looks like I can't assign any value to the variable in the then() method.</p>
  
  <p>the following is the console.log:</p>
  
  <pre><code>Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
  job-list-page.ts:33 Object {id: "invision", name: "INVISONAPP", logo: "assets/images/pictures/invision-logo-square.png", description: "InVision is the world's leading design collaborati…ernote, Twitter, Adobe, Salesforce and many more.", jobs: Array[1]}
  browser_adapter.ts:88 EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot set property 'company' of null
  browser_adapter.ts:78 EXCEPTION: Error: Uncaught (in promise): TypeError: Cannot set property 'company' of nullBrowserDomAdapter.logError @ browser_adapter.ts:78BrowserDomAdapter.logGroup 
  </code></pre>
  
  <p>Really need help, Thank you.</p>