我创建了一个指令来显示下拉菜单(表单选择)。 但是我无法找到标记选定选项的方法。在角度选择指令中获取选定的模型
HTML表单
<div content-selects ng-model="ctrl.contentSelects.riskStatus" selection="oneWMS.riskStatusId"></div> <!-- oneWMS.riskStatusId -->
指令
function contentSelects(){
return {
restrict: 'AE',
templateUrl: '/app/Directives/contentSelects.tpl.html',
replace:true,
scope: {
ngModel: '=',
selection: '='
},
controller:function($scope){
},
link: function (scope, element, attrs) {
scope.selectedModel = scope.ngModel[attrs.selection];
scope.isChanged = function() {
//console.log("changed");
}
element.removeAttr('id');
}
};
}// end function contentSelects
这是我不明白:该指令模板
<div class="input-group">
<select id="{{id}}">
<option value="model.refId" ng-repeat="model in ngModel track by model.refId" ng-model="ngModel[selection]" >{{model.value}} *** {{selection}} *** {{ngModel[selection]}}</option>
</select>
</div>
在实际的价值,{{ngModel[selection]}}
给我什么我想要(目标模型行),但是当绑定到ng模型时,它不会检索任何东西ing:/
ng-model="ngModel[selection]"
它有什么问题?使用大括号打破它当然...
可你把Plunkr你的代码? – lvarayut
显示您的数据样本。您是否尝试过指令外的'
这是我的Plunkr http://plnkr.co/edit/ Na0JmaGZQDPtw6SeBDd4 – Underfrog