我试图在我可爱的Angular / Typescript代码中迭代一个对象列表,但由于某种原因它甚至没有尝试这样做。这是代码:
businessList: RemoteDataSet<BusinessModel>;
businessModel: BusinessModel;
this.businessList.forEach( bl => {
console.log("in foreach");
if (bl.id == this.user.businessId) {
console.log("they are equal");
this.businessModel = bl;
}
else {
console.log("They are not equal");
}
});
我已经确认this.businessList有数据(约40项)。即便如此,它也不会迭代一次。我显然对Angular和Typescript很新,但这似乎是正确的。我错过了什么?
答案 0 :(得分:1)
也许尝试angular.forEach
方法?
forEachFunction = () => {
angular.forEach(this.businessList, (value, key) => {
if (value.id == this.user.businessId) {
console.log("they are equal");
this.businessModel = value;
}
else {
console.log("They are not equal");
}
});
};