How do I access an object in a different module in AngularJS? -


i have 2 modules:

angular.module('test1', [])     .run(function() {         var numbers = [1, 2, 3,4];         // more operations on numbers here     });  angular.module('test2', [])     .run(function() {         // want edit or iterate on numbers here     }); 

i want able edit variable numbers in test2 module. i'm extremely new angular seems easiest way put numbers in $rootscope doesn't seem desirable.

what's idiomatic way achieve this? make numbers .value()? make service? make 'editor' depend on 'test' (a concept still trying grasp)?

you need service pass data. here example how can try it.

var app = angular.module('app', ['access','test1','test2']); angular.module('access', [])     .service('accessservice', function() {         this.numbers = [1, 2, 3,4];         // more operations on numbers here     });  angular.module('test1', [])     .run(function(accessservice) {         var numbers = accessservice.number;         // more operations on numbers here     });  angular.module('test2', [])     .run(function(accessservice) {        accessservice.numbers.foreach(function(number){          console.log(number)        })     }); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -