如何将所选属性添加到 ng-repeated 下拉表单?
How to add selected attribute to ng-repeated dropdown form?
我有一个表单可以根据一些 JSON 数据构建多个小部件。该表单的一部分是 select 下拉菜单,某些项目默认具有不同的选项 select。
即:
object 1 {
tag: "products"
}
ng-repeat 小部件中的 select 下拉菜单
<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>
^ 如果这是 object 1,我需要 products 选项来获得 selected
属性。
到目前为止我已经尝试过,但没有奏效,但是你可以看到我的想法:
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>
控制器
this.selectedTag= function(s) {
console.log(s);
if (s = 'news'){
return 'selected';
}
}
你会怎么做?
在这里找到答案:Initializing select with AngularJS and ng-repeat
<option ng-selected="{{operator.value == filterCondition.operator}}"
ng-repeat="operator in operators"
value="{{operator.value}}">
所以就我而言:
<option value="products"
ng-selected="{{stuff.tag == 'products'}}">products</option>
我有一个表单可以根据一些 JSON 数据构建多个小部件。该表单的一部分是 select 下拉菜单,某些项目默认具有不同的选项 select。
即:
object 1 {
tag: "products"
}
ng-repeat 小部件中的 select 下拉菜单
<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>
^ 如果这是 object 1,我需要 products 选项来获得 selected
属性。
到目前为止我已经尝试过,但没有奏效,但是你可以看到我的想法:
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>
控制器
this.selectedTag= function(s) {
console.log(s);
if (s = 'news'){
return 'selected';
}
}
你会怎么做?
在这里找到答案:Initializing select with AngularJS and ng-repeat
<option ng-selected="{{operator.value == filterCondition.operator}}"
ng-repeat="operator in operators"
value="{{operator.value}}">
所以就我而言:
<option value="products"
ng-selected="{{stuff.tag == 'products'}}">products</option>