Reputation: 11
I am trying to use a pipe inside a foreach loop in my angular component. My array is populated and so is each item of the array when I debug it
console.log(this.blog);
this.relatedLinks = this.blog.related;
this.relatedLinks.forEach(function (link) {
this.newlink = this.removeSpace.transform(link);
this.relatedBlogList = this.Blogs.filter(blog => blog.title === this.newlink);
});
},
But while applying the pipe I get the following error: ERROR TypeError: Cannot read property 'removeSpace' of undefined.
Upvotes: 0
Views: 2464
Reputation: 483
I think this
is not accessible inside the foreach
. Try this and post back with progress.
console.log(this.blog);
this.relatedLinks = this.blog.related;
let self = this;
this.relatedLinks.forEach(function (link) {
this.newlink = self.removeSpace.transform(link);
this.relatedBlogList = this.Blogs.filter(blog => blog.title === this.newlink);
});
},
Upvotes: 1