0
我想在指令中設置modelvalue Null,在更改複選框選中或未選中。設置模型在指令中是空的angularJS
HTML
<input type="checkbox" ng-model="isCheck" />
<select ng-model="empNmae" ng-setempty="isCheck"
ng-options="em.Value as em.Name for em in emp">
<option value="">Select
</select>
{{empNmae}}
JS
// Code goes here
var app=angular.module('myApp',[]);
app.controller("mycntrl", function ($scope) {
$scope.emp=[{
"Name":"Amit",
"Value":101
},{
"Name":"Amit2",
"Value":103
},{
"Name":"Amit3",
"Value":102
}];
$scope.empNmae=102;
$scope.isCheck=true;
});
app.directive('ngSetempty', function() {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope,element, attrs, ctrl) {
scope.$watch(attrs.ngSetempty, function() {
var getChekc=this.last;
if(getChekc){
// set Model is NULL
}
});
}
};
});
如果複選框被選中,然後我想設置的模型是空的選擇框。 Plunker
但我怎麼知道「empNmae」。它會因不同的控制而不同,因爲我將在多重控制上使用此指令。 – 2015-02-11 10:30:14