javascript - How to retain $scope value once we navigate from one page to another in angularjs -
i have 2 controllers in file. whenever navigate 1 page page, scope values empty. here how declare controllers:
var app = angular.module('name',[]); app.controller('ctrl1',function($scope){}); app.controller('ctrl2',function($scope){});
the above code works fine in 1 html, when navigate html, can't access $scope values in controller.
any appreciated.
changing page wholesale forces angular app reload, , why losing scope. obviously, less desirable. needs happen this:
- your base page loads (index.html) , app lives on page. not contain content.
- your app calls default route , loads html partial page in main ng-view. route should contain controller reference should operate on view.
- when need load new information on screen, load partial ng-view via route, along associated controller.
there plenty of examples out there choose show how this. stuff "year of moo" comes mind. pick 1 , go it.
Comments
Post a Comment