I'm trying to implement a filter in Angular 2 class, but i'm getting an error for some reason. I'm not able to filter and return the results.
Class code:
employee = [
{ "empId": "59C", "empDesc": "Software","location":"Dallas"},
{ "empId": "AMI", "empDesc": "Hardware", "location":"San Francisco"}
];
companies : any = [];
comapny : any = [];
test:string="varun";
companyId = this.employee[0].empId;
constructor(){
for (let c of this.employee) {
this.companies.push({
empDesc: c.empDesc,
empId: c.empId
})
};
console.log("Companies",this.companies);
}
getCompanies(companies){
if (this.companyId) {
var filtered = companies.filter(function (company) {
return company.companyId === this.companyId;
});
return filtered[0];
}
}
this.company = this.getCompanies(this.companies);
console.log("Filtered company", this.company);
Plunker link