Answer the question
In order to leave comments, you need to log in
Why does the scope change from the second call when writing a directive?
(function () {
'use strict';
angular
.module('app.widgets')
.directive('pagination', pagination);
function pagination() {
var directive = {
scope: {
offset: "="
},
restrict: 'EA',
link:link,
template:' <button>Read more<button>'
};
return directive;
function link(scope,element,attrs){
element.bind('click', function () {
++scope.offset;
scope.$apply();
});
}
}
})();
<pagination offset="vm.filters.offset"/>
$scope.$watch('vm.filters.offset',function(oldVal,newVal){
console.log(newVal);
});
Answer the question
In order to leave comments, you need to log in
$scope.$watch('vm.filters.offset',function(newVal, oldVal){
console.log(newVal);
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question