I am currently working on a form that dynamically generates multiple widgets based on JSON data. One specific part of the form includes a select dropdown, with some items requiring specific options to be selected by default.
For example:
object 1 {
tag: "products"
}
In the ng-repeat widget, the select dropdown looks like this:
<select class="btn-success form-control">
<option value="companies">companies</option>
<option value="news">news</option>
<option value="people">people</option>
<option value="products">products</option>
</select>
If this is object 1, I want the products option to be automatically selected with the selected
attribute.
Here's what I have attempted so far, although it has not yielded the desired results:
HTML
ng-repeat="stuff in stuffs"...
<select class="btn-success form-control">
<option value="companies">companies</option>
<option ng-if="widget.selectedTag(stuff.tag)" value="news">news</option>
<option value="people">people</option>
<option value="products">products</option>
</select>
Controller
this.selectedTag= function(s) {
console.log(s);
if (s = 'news'){
return 'selected';
}
}
How would you approach solving this issue?