javascript - Isolate scope value is replaced only if it exists - AngularJS Directive -
template:
<ui-print text="print" panel="#paper1" wait-for-data="adc.waitfordata" callfront-fn="adc.somefunction()"></ui-print> <ui-print text="print" panel="#paper2"></ui-print>
directive:
scope: { text: '@', panel: '@', callfrontfn: '&', waitfordata: '=' }, link: function($scope) { var invokeprint = function(panel) { $window.print(); $scope.waitfordata = true; } $scope.printpanel = function(panel) { if (!$scope.waitfordata) { invokeprint(panel); } else { $scope.callfrontfn(); } }; $scope.$watch('waitfordata', function(n) { if (n === false) { invokeprint($scope.panel); } }); }
hi guys, trying understand how isolate scope works here. if @ above code there 2 element directives. 1 has waitfordata , other doesn't.
in 2nd directive, when invokeprint()
, there $scope.waitfordata=true
, not triggering $watch
. in 1st directive does.
is when isolate scope not passed value cannot replaced in directive? not understand why behaving that.
i wanted know why watch not triggered in 2nd directive when $scope.waitfordata = true
, triggered in 1st directive.
sorry not post entire code due security reasons. code needs debugged.
thanks in advance!!!
waitfordata: '='
means require variable waitfordata. if don't supply 1 wont break straight away break try set value. open console , see error messages. if wish value optional append question mark so:
waitfordata: '=?'
now if change waitfordata variable in second directive trigger watch. should append question mark of optional variables or teh directive break try , use them.
Comments
Post a Comment