angularjs - Is it possible to call controller if ng-if condition is true? -


i have 2 controllers on same page. trying achieve if specific value 1 call controller 1 , if 0 controller 2. problem getting value inside controllers not accessible outside controller, how can achieve this?

this case calls service, can shared between controllers.

all have inject service both controllers , update variable in service.

angular.module('app').service('myservice', function() {   var self = this;   self.isactive;    self.setactive = function(val) {      self.isactive = val;   };    self.getactive = function() {     return self.isactive; }) . controller('first', function(myservice) {   var isactive = myservice.getactive(); }) . controller('second', function(myservice) {   var isactive = myservice.getactive(); }) 

both controllers have same value, have handle managing them during life cycle of app via controllers.

note can want in service in terms of logic, have share service required controllers. more function handle logic splitting different controllers.

// inside service self.handleactive = function(isactive) {   if (isactive) {     //   } else {     // other   } }; 

Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -