简体   繁体   English

在角度6中找不到类型为“对象”的其他支持对象“ [对象对象]”

[英]Cannot find a differ supporting object '[object Object]' of type 'object' in angular 6

I'm new to angular 6. I want to display the contents as key (key as label name ) and value in select options. 我刚接触angular6。我想在选择选项中将内容显示为键(键为label name)和值。 I'm able to get JsonObject from restcontroller but unable to process in angular. 我可以从restcontroller获取JsonObject,但无法以角度进行处理。 here is my code. 这是我的代码。

import { MapHeader } from '../../models/mapheader';
headerMapper(){
    this.clientService.getHeaders().subscribe(
        res => {
            console.log(res.json());
            this.mapper = Array.of(res.json());
            console.log(this.mapper);
            this.ismapped = false;
        }
    );
}

mapperheader.ts mapperheader.ts

export class MapHeader {
    public AOV: string;
    public budget: string;
    public CPO: string;
}

.html html的

<div>
    <form *ngFor="let map of mapper">
        <mat-form-field>
            <mat-select placeholder="{{map}}">
                <!--<mat-option>None</mat-option>-->
                <mat-option *ngFor="let option of map" [value]="option">{{option}}</mat-option>
            </mat-select>
        </mat-form-field>
    </form>
</div>

console.log(res.json()) prints the below console.log(res.json())显示以下内容

Object
AOV:
(19) ["sessions", "Budget", "CTR"]
CPC:
(19) ["sessions", "Budget", "CTR"]
CPO:
(19) ["sessions", "Budget", "CTR"]

console.log(this.mapper) this prints the below console.log(this.mapper)显示以下内容

 Array(1)
    0:
    AOV:
    (19) ["sessions", "Budget", "CTR"]
    CPC:
    (19) ["sessions", "Budget", "CTR"]
    CPO:
    (19) ["sessions", "Budget", "CTR"]

ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
    at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoCheck (common.js:3138)
    at checkAndUpdateDirectiveInline (core.js:9251)
    at checkAndUpdateNodeInline (core.js:10512)
    at checkAndUpdateNode (core.js:10474)
    at debugCheckAndUpdateNode (core.js:11107)
    at debugCheckDirectivesFn (core.js:11067)
    at Object.eval [as updateDirectives] (AddNewClientComponent.html:47)
    at Object.debugUpdateDirectives [as updateDirectives] (core.js:11059)
    at checkAndUpdateView (core.js:10456)
    at callViewAction (core.js:10697)
View_AddNewClientComponent_3 @ AddNewClientComponent.html:45

Expected result 预期结果

AOV as label and sessions,ctr,budget as select option AOV作为标签和会话,ctr,budget作为选择选项

You need to process your response in order to have an array as output: 您需要处理响应才能将数组作为输出:

   import { MapHeader } from '../../models/mapheader';
    headerMapper(){
        this.clientService.getHeaders().pipe(map(res => res.json())).subscribe(
            res => {
                console.log(res.json());
                this.mapper = Object.keys(res).map( elm => {elm : res[elm]}) ;
                console.log(this.mapper);
                this.ismapped = false;
            }
        );
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:找不到支持 object '[object Object]' 类型 'object' 的差异 - Err: Cannot find a differ supporting object '[object Object]' of type 'object' 在 Angular 8 中找不到不同的支持 object '[object Object] - Cannot find a differ supporting object '[object Object] in Angular 8 Angular 7 找不到类型为“object”的不同支持对象“[object Object]”。 NgFor 只支持绑定到 Iterables,比如 Arrays - Angular 7 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays Angular 9 找不到支持“对象”类型的 object“[对象对象]”的不同。 NgFor 仅支持绑定到诸如 Arrays 之类的 Iterables - Angular 9 Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays 错误错误:在 Angular 项目上找不到支持类型为“object”的 object“[object Object]”的差异 - ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object' on Angular Project 找不到类型为“object”的不同支持对象“[object Object]”。 NgFor 仅支持绑定到可迭代对象,例如数组。 [Angular 8] - Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.[Angular 8] 错误找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到可迭代对象,例如数组 - ERROR Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays 错误:找不到类型为“对象”的其他支持对象“ [对象对象]”。 NgFor仅支持绑定到Iterables - Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables 流星集合中找不到类型为“对象”的其他支持对象“ [对象对象]” - Cannot find a differ supporting object '[object Object]' of type 'object' , Error in meteor Collections 找不到支持“object”类型的 object“[object Object]”的不同,但它已经是一个数组 - Cannot find a differ supporting object '[object Object]' of type 'object' , but it's already an array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM