Answer the question
In order to leave comments, you need to log in
Why doesn't the $watch in the directive work?
Good day.
I am writing a directive, the essence of which is to call a modal window and send data to the server from a form in this window. I show the window using the Modal directive from Bootstrap components for Angular ( angular-ui.github.io/bootstrap ).
'templates/modal/addCom.html'
<select class="form-control" ng-model="selected">
<option ng-repeat="type in types" value="{{type}}">{{type.comment}}</option>
</select>
app.directive('addCom',function($modal,addComService){
return {
restrict: 'A',
link : function($scope, $element, $attributes){
$element.on('click',function(){
modal();
});
var modal = function(){
var modalInstance = $modal.open({
animation: $scope.animationsEnabled,
templateUrl: 'templates/modal/addCom.html',
controller: function($scope,$modalInstance){
$scope.selected = {};
$scope.disabled = true;
$scope.$watch(
function(){
return $scope.selected;
},
function(newVal,oldVal){
//срабатывает только при вызове окна
console.log(newVal);
//срабатывает только при вызове окна
console.log(oldVal);
},
true
);
}
})
};
}
}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question