juristr / juristr.github.com

My personal website and blog
http://juristr.com
21 stars 16 forks source link

how to get array value to frontend using angular5 and mongodb #15

Closed prudhvi94910 closed 5 years ago

prudhvi94910 commented 5 years ago

Hai guys can you please anyone tellme, I have number of users in my mongodb, i need to get title in Array of that users to frontend. can anyone please tellme where the error occurs and what i need to put. thanks in advance.

my HTML component <label> <mat-card class="example-card" *ngFor="let articles of userDetails">{{articles.title}} </label>

my TS component ngOnInit() { this.accountService.getWeb().subscribe( response => { console.log(response); this.userDetails = response; }, err => { console.error('User Not found'); }) }

accountservice.ts getWeb() { return this.http.post(this.apiPath + 'user/getWeb', {}); }

usercontroller.js //Getting title in Users userRouter.post('/getWeb', (req, res) => { Collections.user.find({}, {"article":1}, function (err, result) { if (err) return res.status(500).send("There was a problem finding the user"); if (result) { return res.status(200).send(result); } else { return res.status(500).send("User Not Found with Details: " + JSON.stringify(user)); } }); });

my mongodb structure is: article:Array 0:Object title:"hello"

juristr commented 5 years ago

Hey, this is probably the wrong repository. Please post on Stackoverflow.