I'm a newbie in angular 4. I'm facing a problem with *ngFor with HTML drop-down select and option.
I have categories array-object -
categories = [
{ id:1, title: 'c/c++'},
{ id:2, title: 'JavaScript'},
{ id:3, title: 'Angular'},
{ id:4, title: 'Node'}
];
I want to show title in the dropdown but I want to get the category id in the ngModel.
Like - in HTML view show all title in a dropdown list, but when I select one of them then ngModel will get that category id.
i.e: I select JavaScript, ngModel will get the id of JavaScript category.
I search much time on google but I could not find any solution.
Here is HTML code -
<label>Category</label>
<select [(ngModel)]="post.category_id" class="form-control select2" style="width: 100%;">
<option *ngFor="let category of categories">{{ category.title}}</option>
</select>