I have this HTML element:
<tags-input
ng-model="film.genre"
display-property="name"
key-property="id"
placeholder="Genre"
replace-spaces-with-dashes="false">
<auto-complete source="loadGenres($query)"></auto-complete>
</tags-input>
This creates a similar tag input field as on Stackoverflow. This is the package being used http://mbenford.github.io/ngTagsInput/
Now loadGenres will return an object like so {name: "Genre name", id: 4}. And it will be stored into film.genre as such. Which is a problem because the API service expects film.genre = [4, ...] basically it must be an array of id's.
I'm not completely sure how to fix this. I tried to make an empty array in my newFilm() method loop the film.genre and add id's from it to that array than assign it to film.genre. However this does not work as when I output the film after doing that I still get an array of Objects where name: id by some logic.
What I get in film.genre:
"genre": [ 0: { "id": 1, "name": "Action" }, 1: { "id": 5, "name": "Comedy" }, ..]
What I need:
"genre" : [1, 5]
film.genre.map(g => g.id)– Phil May 13 '16 at 4:56$scope.film.genreand by all accounts of the ngTagsInput documentation, it should be an array – Phil May 13 '16 at 5:02