I have the following code:
html template:
<button class="" ng-click="item_popup.toggle()"/>
inside one directive:
app.directive('itemPopup', ['$sce', '$timeout', function($sce, $timeout){
return {
restrict: 'E',
replace: true,
templateUrl: $sce.trustAsResourceUrl('/'),
link: function(scope, el, attrs) {
toggle = function(){
item.toggle = scope.items.checked == 0 ? 1 : 0
}
}]);
and app:
app.directive('item', ['$filter','$timeout', function($filter,$timeout){
scope.$watch('item.toggle', function(newValue,oldValue){
if(newValue!=undefined && oldValue!=undefined && oldValue != newValue){
// Do something
}
});
}]);
the issue here is that each time toggle function is called, scope.$watch is triggered twice.
i tried to check some other answers, like:
Angular expressions in $watch trigger twice
$rootScope.$watch triggered twice
but non of them gives the answer.