Thursday, 20 April 2017

Getting an Array with Angular 2 from mongoose mongoDB database

I am trying to retrieve my Members collection in my angular 2 front end.

in my routes I have:

router.post('/memberprofile', function (req, res) {
Member.find({}, function (err, members){
    if (err){
    console.log(err);
}else{
  res.json(members);
  console.log('retrieved members', members.length);
  console.log(members);
}
});
});

I am attempting to GET it by using this code:

this.http.get('http://localhost:3000/users/memberprofile')
              .subscribe(result => this.result = result.json());
              console.log(this.result);
               }

I am then given the following error in the console:

SyntaxError: Unexpected token < in JSON at position 0

My question is, how am I able to push the array to the front end, I hope to eventually place the result into a table but at the moment if anyone can work out why I cant console log this array that would be great.

Thanks!



via Alex Zabiela

No comments:

Post a Comment