Answer the question
In order to leave comments, you need to log in
How to make an attribute in your directive that catches changes to variables?
Hello!
I make a directive that will be an attribute, in which the value of the attribute, depending on the variable located in $scope, gave true / false. This is how ng-class works for example. I have just a string in the attribute value and when the variable changes, the value of the expression is not calculated.
Directive:
define(['angular'], function(angular) {
angular.module('ids.focus', []).directive('focus', function() {
return {
link: function($scope, element, attrs){
console.log($scope.focus);
},
scope: {
focus: '='
}
}
});
});
<input type="text" ng-model="item.name" focus="item === editItem"/>
Answer the question
In order to leave comments, you need to log in
define(['angular'], function(angular) {
angular.module('ids.focus', []).directive('focus', function() {
return {
link: function($scope, element, attrs){
$scope.$watch('focus', function(){
// тут делаете то что вам нужно при изменение переменной
});
},
scope: {
focus: '=focus'
}
}
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question