I am currently working on creating an API service and trying to assign the data to a variable. However, I am facing an issue where the variable is not updating and ends up being undefined when I try to log it after calling the API service.
import {Component,Input,Output,EventEmitter} from 'angular2/core';
import {NgClass,NgFor} from 'angular2/common';
import {Observable} from 'rxjs/Observable';
import {ChangeDetectionStrategy} from 'angular2/core';
import {ValuesPipe} from '../pipes/values';
import {ApiRequestService, Query} from '../services/apiRequestService';
@Component({
selector: 'browsePCLatestRelease',
directives: [NgClass,NgFor],
changeDetection: ChangeDetectionStrategy.OnPush,
pipes: [ ValuesPipe ],
styles: [ require('./browsePCLatestRelease.less') ],
template: require('./browsePCLatestRelease.html')
})
export class browsePCLatestRelease {
public arrayOfKeys;
pcLatestrelease:Array<any> ;
query: Query;
constructor(private _apiService: ApiRequestService) {
}
ngOnInit() {
this.query = this._apiService.createQuery('browsePC.getIssue');
this.query.params({
volume: '60',
issue: '50'
});
this._apiService.execute(this.query)
.subscribe(
data => this.pcLatestrelease=data,
error => console.log(error),
() => console.log('pcLatestrelease retrieved')
);
console.log('this.pcLatestrelease');
console.log(this.pcLatestrelease);
}
}
HTML
<div *ngFor = "#thisRelease of pcLatestrelease">
{{thisRelease.title}}
</div>
If anyone has any insights or solutions, I would appreciate your help. Thank you in advance.