How would one run two controllers at the same time AngularJS -


i'm making webapp in angularjs (using yeoman), , have loop add 1 counter every second. worked fine, until needed multiple tabs multiple controllers. tried running loop in main controller, didn't work.

i want gameloop function in moneyctrl run @ times, there better place put function?

does have idea of how this, or @ least achieve same effect?

github project

you can put gameloop function on run block.

angular.module('incrementalapp', ['nganimate', 'ngcookies', 'ngresource',     'ngroute', 'ngsanitize', 'ngtouch' ]).config(function($routeprovider) {     //... }).run(function($rootscope, moneyservice, vars){      var stop;      $rootscope.loop = function() {         if (angular.isdefined(stop) ) {             return;         }         stop = $interval(function() {             angular.foreach(vars.clickers, function(clicker){                 moneyservice.addmoney((clicker.amount * clicker.production)/vars.fps);             });          }, 1000/vars.fps);          $rootscope.stoploop = function() {             if (angular.isdefined(stop)) {                 $interval.cancel(stop);                 stop = undefined;             }         };          $rootscope.$on('$destroy', function() {           // make sure interval destroyed           $scope.stopfight();         });     };    $scope.loop(); }) 

and use service add money can require service on each controller.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -