cordova - If i am having the 5 pages with 5 controllers in angularjs -


hi having 5 pages 5 controllers , using 1 service using injection in every controller . possible without editing code in views , controllers stop services functionality writing code anywhere once in of 1 view or controller ? example having app uses server retrieve data , can writing simple code restrict service instead of server can access localdata ?

all angular services application singletons. means, can change state of service once, , change 'visible' it's users.

the service gets instantiated when application ask it. while service exists, controllers, etc. receive reference same service instance (i still expect service garbage collected when references service lost).

this means, after initialize service, controllers can invoke methods, etc. - on same instance, visible other instances.

here's jsfiddle showing concept. when value in factory object changed in 1 controller, visible throughout application. both controllers use modified value of testfactory.name, gets modified during initialization of helloctrl. easy add 2 buttons count clicks in field of factory's object , make both controllers display value changes.

function helloctrl($scope, testfactory) {     $scope.fromfactory = testfactory.sayhello();     testfactory.setname("ellitereit");     $scope.newvalue = testfactory.sayhello(); }  function goodbyectrl($scope, testfactory) {     $scope.fromfactory = testfactory.saygoodbye(); } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -