Angular 错误:找不到不同的支持对象';[对象对象]';类型为';对象';角度6
我有一个问题。我寻找其他的解决办法,但没有找到对我有帮助的 错误是: 错误:找不到不同的支持对象“[object]” 类型为“对象”。NgFor仅支持绑定到Iterables,例如 数组 我的模特Angular 错误:找不到不同的支持对象';[对象对象]';类型为';对象';角度6,angular,multidimensional-array,angularjs-directive,angular6,Angular,Multidimensional Array,Angularjs Directive,Angular6,我有一个问题。我寻找其他的解决办法,但没有找到对我有帮助的 错误是: 错误:找不到不同的支持对象“[object]” 类型为“对象”。NgFor仅支持绑定到Iterables,例如 数组 我的模特 export interface CEP { complemento: string; bairro: string; cidade: string; logradouro?: string; estado_info?: string[]; cep: s
export interface CEP {
complemento: string;
bairro: string;
cidade: string;
logradouro?: string;
estado_info?: string[];
cep: string;
cidade_info?:string[];
estado: string;
}
searchCEP() {
console.log(this.cepDigitado);
this.cepService.ceps(this.cepDigitado)
.subscribe(cep => {
this.cep = cep; console.log(this.cep); /*this.cepArray.push(this.cep);*/ console.log(this.cepArray);
},
error => { alert("Erro") });
}
我的服务
import { Injectable } from '@angular/core';
import { CEP } from './cep/cep.model';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
//import { map, tap } from 'rxjs/operators';
@Injectable()
export class CEPSerivce {
constructor(private http: HttpClient) {}
ceps(numCEP: string): Observable<CEP[]> {
return this.http.get<CEP[]>
(`https://api.postmon.com.br/v1/cep/${numCEP}`);
}
}
My component.html
<table>
<tr *ngFor="let c of cep">
<td>{{c.cidade}}</td>
</tr>
</table>
*ngFor
指令只对可编辑对象起作用。如果要循环对象的所有属性,可以使用keyValue
pipe
<table>
<tr *ngFor="let item of cep | keyValue">
<td>{{item.key}} {{item.value}}</td>
</tr>
</table>
您好,现在出现了此错误:未捕获错误:模板分析错误:找不到管道“keyValue”(“{c.key}}}{{c.value}”):请确保您有angular 6.1+我的版本:依赖项:“{@angular/animations”:“^6.0.3”,“@angular/common”:“^6.0.3”,“@angular/compiler”:“^6.0.3”“,“@angular/core”:“^6.0.3”,“@angular/forms”:“^6.0.3”,“@angular/http”:“^6.0.3”,“@angular/platform browser”:“^6.0.3”,“@angular/router”:“^6.0.3”,“core js”:“^2.5.4”,“rxjs”:“^6.0.0”,“zone.js”:“^0.8.26”},第二个解决方案也不起作用,我想展示几乎所有的data@Todd7更新到所有angular软件包的
6.1.7
版本,如果使用angular CLI,请执行ng update@angular/core
命令
<table>
<tr *ngFor="let item of cep | keyValue">
<td>{{item.key}} {{item.value}}</td>
</tr>
</table>
ceps: any[] = []
searchCEP() {
console.log(this.cepDigitado);
this.cepService.ceps(this.cepDigitado)
.subscribe(cep => {
this.ceps = [cep]; console.log(this.cep);
})
}