N
N
nzk2018-08-30 13:13:58
Angular
nzk, 2018-08-30 13:13:58

_this.posts.filter is not a function?

I did not make a big filter, but because of this, the following error appeared:

ERROR TypeError: _this.posts.filter is not a function
    at SafeSubscriber.eval [as _next] (posts.component.ts:95)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:238)
    at SafeSubscriber.next (Subscriber.js:185)
    at Subscriber._next (Subscriber.js:125)
    at Subscriber.next (Subscriber.js:89)
    at DoSubscriber._next (do.js:88)
    at DoSubscriber.Subscriber.next (Subscriber.js:89)
    at MapSubscriber._next (map.js:83)
    at MapSubscriber.Subscriber.next (Subscriber.js:89)
    at RefCountSubscriber.Subscriber._next (Subscriber.js:125)

What have I done wrong?
getPost(page: number) {
    let filteredPosts;
    if (this.servPost) {
      this.servPost.getPosts(page).subscribe(
        post => {
          this.servPost = post;
          this.filteredPosts = this.posts.filter(
            (post) => post.name != null
          );
        }
      );
    }
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2018-08-30
@Xuxicheta

this.posts is not an array. Why, see for yourself. There is nothing else in your passage about him.
Maybe you should have done
this.posts = post || [];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question