喜的特性“SUBCRIBE”我是新来AngularJs 2.AppComponent.html:1错误类型错误:无法读取未定义
我创建简单的应用程序来读取Github的API。
当我开始用下面的文件的应用程序,我收到以下错误:
AppComponent.html:1个错误类型错误:未定义
下面是无法读取属性“SUBCRIBE”我的服务和组件ts文件。
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 = "client_id";
private client_secret = "client_secret";
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);
})
}
}
非常感谢您提前给出的解决方案。
@Momin请记住,当你过去的代码,删除像client_id和client_secret这样的敏感信息。我现在已经为你删除了这个,但是请记住这个。 – fredrik
好的!但我在那里做? – Momin
@Momin你在这个问题中写的代码包含“client_id”和“client_secret”。当你写问题时不要包含任何敏感信息时请小心。我建议你去https://github.com/settings/tokens并删除旧的并创建一个新的。 – fredrik