javascript - AngularJS $scope is not updating in DOM -


i have following codes :

the state (lets make short simplicity purposes)

.state('foo', {     url: '/foo',     templateurl: 'path/to/template.html',     controller:'fooctrl', }) 

the controller

controller = function($scope){     // not actual code     $scope.barcount } 

template.html

<div>     <span>{{ barcount }}</span> // updating </div> 

other html partial

<div ng-controller="fooctrl">     <span>{{ barcount }}</span> // **not** updating </div> 

i have scope variable on controller. 2-way binding working fine on template declared on state controller. not on other partial template in binded controller using ng-controller.

is kind of bug? or missing something? thanks.

you have 1 controller 2 instances of controller. each time use ng-controller or declare in differents views new instance created, controllers in differents scopes. best way share data between controller services, because these singleton, have 1 instance. example:

angular.module('app')  .factory('fooservice', [function(){   var bar = 'shared data';   return {     getbar: function(){       return bar;     }   }; }])  .controller('foocontroller', ['fooservice', function(fooservice){   this.barcount = fooservice.getbar();   // or use $scope.barcount = fooservice.getbar(); }]; 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -