【问题标题】:Angular2: Trying to diff '[object Object]' while calling values back from dbAngular2:在从 db 回调值时尝试区分“[object Object]”
【发布时间】:2016-10-20 19:30:42
【问题描述】:

我正在尝试根据另一个选择的命名公司过滤我选择的命名分支的值,但是当我尝试更新分支数组的值时出现错误:

试图区分 [object Object]

我的服务:

getCCBs() {
    return this._http.get('CustomerCompanyBranches/GetCCBs').map(res => res.json());
}

我的组件:

export class CompanyComponent {

companies: CustomerCompany[];
branches: any;

constructor(private _ser: DemoService) {}

getComps() {
    this._ser.getCCs().subscribe(res => this.companies = res);
}
getCBran() {
    this._ser.getCCBs().subscribe(res => this.branches = res);
}

onSelect(customercompanyname) {
    console.log(customercompanyname);
    this.branches = this._ser.getCCBs().subscribe(res => res.find(br => br.CustomerCompanyBranchName === customercompanyname));
}

ngOnInit() {
    this.getComps();
    this.getCBran();
}

}

我的html:

<label>Company:</label>
<select (change)="onSelect(t.value)" #t>
    <option value="0">--Select--</option>
    <option *ngFor="#c of companies" value={{c.CustomerCompanyName}}>{{c.CustomerCompanyName}}</option>
</select>
{{t.value}}
<br /><br />
<div >
    <label>Branch:</label>
    <select>
        <option *ngFor="#b of branches">
        {{b.CustomerCompanyBranchAddress}}
        </option>
    </select>
</div>

【问题讨论】:

    标签: html asp.net-mvc angular typescript


    【解决方案1】:

    因为您需要在订阅功能中进行分配。

    onSelect(customercompanyname) {
            console.log(customercompanyname);
            this._ser.getCCBs().subscribe(res => res.find(br => { this.branches =  = br.CustomerCompanyBranchName === customercompanyname } ));
        }
    

    【讨论】:

    • 它说“尝试区分来自 db 的值时出错”...我现在该怎么办?
    猜你喜欢
    • 2016-11-08
    • 2021-01-04
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    • 2013-12-04
    • 2019-08-08
    • 2017-11-18
    相关资源
    最近更新 更多