javascript - Angular scope.$watch not working in directive -


i have angular directive scope.$watch not working, know value changing. here's directive:

   var stepformdirective = function ($timeout, $sce, datafactory) {         return {             replace: false,             restrict: 'ae',             scope: {                 currentstep: "=",                 title: "="             },             template: '<h3>{{title}}</h3><form class="step-form"></form>',             compile: function (telem, attrs) {                 return function (scope, elem, attrs) {                     scope                             .$watch(                                     function(){return scope.currentstep;},                                     function (newvalue) {                                         var stepformfields = array();                                         stepformfields.push($sce.trustashtml("<p>fields</p>"));                                         alert(scope.currentstep);                                     }                             );                 };             }         };     }; 

here's tag:

<div title="'test'" currentstep="currentcontext.currentstep"></div>

i know currentcontext.currentstep changing, because have on page , updates:

<pre>{{currentcontext.currentstep | json}}</pre>

the alert gets called first time, when value changes (evidenced bit in pre tags) alert not called again , have no js console errors.

the output step (it's data type) is:

{   "identifier": "830abacc-5f88-4f9a-a368-d8184adae70d",   "name": "test 1",   "action": {     "name": "approval",     "description": "approve",     "instructions": "select 'approved' or 'denied'",     "validoutcomes": [       {         "outcome": "approved",         "display": "approved",         "id": "approved"       },       {         "outcome": "denied",         "display": "denied",         "id": "denied"       }     ]   ... 

try use $watch method third argument set true (objectequality):

$watch('currentstep', function(newvalue){...}, true); 

or use $watchcollection:

$watchcollection('currentstep', function(newvalue){...}) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -