Binding 角度2:组件可重用性。无法绑定数据

Binding 角度2:组件可重用性。无法绑定数据,binding,components,angular,reusability,Binding,Components,Angular,Reusability,我试图在我的组件中绑定数据,以便可以使用select和select department for employee。 我的组件代码如下所示: getAll(){ if(this.searchString.length > 0){ this._employeeService.getEmployeesBySearch(this.searchString,this.pageNumber, this.pageSize).subscribe(data => {thi

我试图在我的组件中绑定数据,以便可以使用select和select department for employee。 我的组件代码如下所示:

  getAll(){
    if(this.searchString.length > 0){
        this._employeeService.getEmployeesBySearch(this.searchString,this.pageNumber, this.pageSize).subscribe(data => {this.bindData(data,this.departments)});
    }else{
         this._employeeService.getEmployees(this.pageNumber, this.pageSize).subscribe(data => {this.bindData(data, this.departments)});
    }
  }


   bindData(data,departments) {
            this.employees = data;
            for (var i = 0; i < this.employees.length; i++) {
                for (var j = 0; j < this.departments.length; j++) {
                    if (this.departments[j].departmentNo == this.employees[i].departmentNo) {
                        this.employees[i].Department = {
                            departmentNo: this.departments[j].departmentNo,
                            departmentName: this.departments[j].departmentName,
                            departmentLocation: this.departments[j].departmentLocation
                        }

                        };
                        break;
                    }
                }
            }
按员工姓名搜索的我的管道外观:

import {Pipe} from 'angular2/core';

@Pipe({
    name: "searchString"   
})
export class SearchPipe{
    transform(value: any, args: string[]): any{
        let filter = args[0].toLocaleLowerCase();
       return filter ? value.filter(employee => employee.employeeName.toLocaleLowerCase().indexOf(filter) != -1) : value;
    }

}

似乎
employees
不是数组。你能核实一下吗?嗨!谢谢你的重播,我在Chrome上看到了这个:{“employeeNo”:4,“departmentNo”:4,“employeeName”:“Branka Bilic”,“salary”:30000.0000,“lastModifyDate”:“2016-02-01T00:00:00”,“Department”:{“departmentNo”:4,“departmentName”:“Sales”,“departmentLocation”:“Pula”}。你是对的,但是我怎样才能把员工转换成数组呢?数据看起来像一个员工,为什么你需要
ngFor
?实际上我有一个员工对象数组,员工对象里面是部门对象。不,它不是一个员工。它原来是这样的:“[{“employeeNo”:4,“departmentNo”:4,“employeeName”:“Branka Bilic”,“salary”:30000.0000,“lastModifyDate”:“2016-02-01T00:00:00”,“Department”:{“departmentNo”:4,“departmentName”:“Sales”,“departmentLocation”:“Pula”}和其他10]”可能是
searchFilter
管道的问题。你能编辑问题并添加管道代码吗?
"[ {
    "employeeNo":4,
    "departmentNo":4,
    "employeeName":"Branka Bilic",
    "salary":30000.0000,
    "lastModifyDate":"2016-02-01T00:00:00",
    "Department":{‌​       
        "departmentNo":4,
        "departmentName":"Sales",
        "departmentLocation":"Pula"
    }, etc...
}]"
import {Pipe} from 'angular2/core';

@Pipe({
    name: "searchString"   
})
export class SearchPipe{
    transform(value: any, args: string[]): any{
        let filter = args[0].toLocaleLowerCase();
       return filter ? value.filter(employee => employee.employeeName.toLocaleLowerCase().indexOf(filter) != -1) : value;
    }

}