Can't assign value to variable using subscribe() method in Angular 2
<p>The promise returns a value but I don't seem to be assigning the value properly in the subscribe method. </p>

<pre><code>import { Component } from '@angular/core';
import { DataService } from '../../shared/data.service';

@Component({
  selector: 'topbar',
  templateUrl: './src/app/components/topbar/topbar.component.html',
  styleUrls: ['./src/app/components/topbar/topbar.component.css'],
  providers: [DataService]
})

export class TopbarComponent {
  companyCount;

  constructor (private dataService: DataService){
    dataService.getCompaniesCount().subscribe(res =&gt; this.companyCount = res.count); //doesn't work
    dataService.getCompaniesCount().subscribe(res =&gt; console.log(res.count)); //works    
  }
}
</code></pre>