I want to set modelvalue Null in directive, on changing checkbox checked or unchecked.
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
}
});
}
};
});
if checkbox is checked , Then I want to set the model is Null for selectbox. Plunker