How to combine posts and users in AngularJS, for example in a database like this. There are 2 data that are the same, namely user_id, then I want to display the username data?
[post: {post_id: 1, user_id: 2, date: 18-05-1997}];
[user: {user_id: 2, fullname: herman, username: herman_man}];
2
Answers
I asked for angular js not angular io
First, the data should be joined and returned from the database/api layer to the front-end.
However, if that is not possible, there are many ways to do this. One simple way is to do a
map
and return a new ViewModel. Something like this:I haven’t executed the code above, it’s meant to be a guide on how to do this. I’ve done something similar in my code.
UPDATE
Here is another SO article with other advanced options to try.