我按照本教程。在从api.github获取用户列表的方式中,我收到错误消息:
找不到其他支持对象“ [object Object]”
我认为它与
<ul>
<li *ngFor = "#user of users">
{{user | json}}
</li>
</ul>
在我的代码中,因为在此之前没有任何错误,并且不确定数据是否来自get请求,只是单击并没有给出任何错误,这是到目前为止的代码
@Component({
selector: 'router',
pipes : [],
template: `
<div>
<form [ngFormModel] = "searchform">
<input type = 'text' [ngFormControl]= 'input1'/>
</form>
<button (click) = "getusers()">Submit</button>
</div>
<div>
<ul>
<li *ngFor = "#user of users">
{{user | json}}
</li>
</ul>
</div>
<router-outlet></router-outlet>
`,
directives: [FORM_DIRECTIVES]
})
export class router {
searchform: ControlGroup;
users: Array<Object>[];
input1: AbstractControl;
constructor(public http: Http, fb: FormBuilder) {
this.searchform = fb.group({
'input1': ['']
})
this.input1 = this.searchform.controls['input1']
}
getusers() {
this.http.get(`https://api.github.com/
search/users?q=${this.input1.value}`)
.map(response => response.json())
.subscribe(
data => this.users = data,
error => console.log(error)
)
}
}
bootstrap(router, [HTTP_PROVIDERS])
慕标5832272
MMTTMM
相关分类