Angular2:在从db调用值时尝试diff'[object Object]'

时间:2016-10-20 11:22:21

标签: html asp.net-mvc angular typescript

我试图在另一个选择命名公司的基础上过滤我选择命名分支的值但是当我尝试更新分支数组的值时,我得到错误:

  

尝试diff [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>

1 个答案:

答案 0 :(得分:1)

因为你需要在订阅功能中进行作业。

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