javascript - Angularjs Directive with Isolated Scope doesn't trigger DOM change outside of directive -


i'm playing around angular directives isolated scopes. i've faced interesting situation. when call function local scope, changes $scope variable content, not affecting dom. in example, add new element $scope.customers list, , not triggering ngrepeat, part of dom not affected ngrepeat items should rendered.

directive code:

function additem() {     scope.add();         items.push({         name: 'new directive customer'     });     scope.$broadcast("refresh");     render(); } ... return {   restrict: 'ea',   scope: {       datasource: '=',       add: '&',     },     link: link }; 

local function code:

$scope.addcustomer = function() {     counter++;     $scope.customers.push({         name: 'new customer' + counter,         street: counter + ' cedar point st.'     });      alert($scope.customers.length); }; 

dom ngrepeat part:

<isolate-scope-with-controller datasource="customers" add="addcustomer()"></isolate-scope-with-controller> <hr /> <div>     <ul>         <li ng-repeat="customer in customers">{{customer.name}}</li>     </ul> </div> 

the alert() show $scope.customers bigger after every button click, ngrepeat won't work on dom.

the full code: http://plnkr.co/edit/8tuzkbkxk0twjsb6i104

my question that, possible trigger dom changes kind of directives somehow?

thanks in advance

your plunkr worked me after removing check event.srcelement.id in directive's click-callback.

 function additem() {       //call external function passed in &       scope.add();        //add new customer local collection       items.push({           name: 'new directive customer'       });         scope.$broadcast("refresh");       render();   } 

in controller have use $scope.$apply make changes appear in template:

    $scope.addcustomer = function() {       $scope.$apply(function(){         counter++;         $scope.customers.push({           name: 'new customer' + counter,           street: counter + ' cedar point st.'         });      }); 

http://plnkr.co/edit/lgmgipiqem2aa8cngkhz?p=preview


Comments