角度:找不到其他支持对象“ [对象对象]”

我按照本教程。在从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])


天涯尽头无女友
浏览 554回答 3
3回答

慕标5832272

我在代码中收到此错误,因为我没有运行JSON.parse(result)。所以我的结果是一个字符串而不是对象数组。即我得到:"[{},{}]"&nbsp;代替:[{},{}]import { Storage } from '@ionic/storage';...private static readonly SERVER = 'server';...getStorage(): Promise {&nbsp; return this.storage.get(LoginService.SERVER);}...this.getStorage()&nbsp; .then((value) => {&nbsp; &nbsp; &nbsp;let servers: Server[] = JSON.parse(value) as Server[];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; );

MMTTMM

输入属性周围缺少方括号可能会导致此错误。例如:Component Foo {&nbsp; &nbsp; @Input()&nbsp; &nbsp; bars: BarType[];}正确:<app-foo [bars]="smth"></app-foo>不正确(触发错误):<app-foo bars="smth"></app-foo>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

AngularJS