Reputation: 460
I'm trying to iterate through a list of objects in my lovely Angular/Typescript code, but for some reason it doesn't even attempt to do so. Here's the code:
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");
}
});
I've verified that this.businessList has data (about 40 items). Even so, it doesn't iterate through even once. I'm obviously pretty new to Angular and Typescript, but this seems right. What am I missing?
Upvotes: 2
Views: 690
Reputation: 199
Maybe try the angular.forEach
method?
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");
}
});
};
Upvotes: 1