这有效:
<p class="form-control-static">{{ctrl.StatusId}}</p>
<div content-selects ng-model="Statuses" selection="2"></div>
这不是
<p class="form-control-static">{{ctrl.StatusId}}</p>
<div content-selects ng-model="Statuses" selection="ctrl.StatusId"></div>
在第一种情况下,{{ctrl.StatusId}}
显示2,我的指令完美无缺。
在第二种情况下,{{ctrl.StatusId}}
也显示2,而我的指令不起作用。
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[scope.selection];
console.log(scope.selectedModel);
scope.isChanged = function () {
//console.log("changed");
}
}
};
如果我使用花括号,则会破坏selection =“{{ctrl.StatusId}}”。我应该给这个属性什么,以便它识别传递的值?