Hi I am new to AngularJs 2.
I am creating simple application to read Github API.
When i am starting the application with the following files, i am getting the following error:
AppComponent.html:1 ERROR TypeError: Cannot read property 'subcribe' of undefined
Below are my service and component ts files.
github.service.ts
import {Injectable} from '@angular/core';
import {Http, Headers} from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class GithubService{
private username: string;
private client_id = "753ff511292d2c809c4a";
private client_secret = "b9687e8f72dcdc57981a938b2f6f9bb098d17c3d";
constructor( private _http: Http){
console.log("Github service is ready...");
this.username = "graphicsmanoj";
}
getUser(){
this._http.get('http://api.github.com/users/'+this.username+'?client_id='+this.client_id+'&client_secret='+this.client_secret).map(res => res.json());
}
}
profile.component.ts
import { Component } from '@angular/core';
import { GithubService } from '../services/github.service';
@Component({
moduleId: module.id,
selector: 'profile',
templateUrl: 'profile.component.html',
})
export class ProfileComponent {
constructor(private _githubService: GithubService){
this._githubService.getUser().subcribe(user => {
console.log(user);
})
}
}
Thank you very much in advance for the solution given.
via Manoj
No comments:
Post a Comment