The promise returns a value but I don't seem to be assigning the value properly in the subscribe method.
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 => this.companyCount = res.count); //doesn't work
dataService.getCompaniesCount().subscribe(res => console.log(res.count)); //works
}
}
console.log(this.companyCount)