0

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.

1 Answer 1

1

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);
        });
  },
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.