javascript - Scope variable not accessible (undefined) - AngularJS -


i setting scope variable in 1 controller, changing location view. in controller of new view scope variable no longer accessible, states 'undefined'. have added simplified version of problem below , appreciate help.

app.controller('logincontroller', function ($scope,$location){     $scope.loginuser = function (user) {         $scope.userid = "userid";        $location.path('/view3');     } }); 

controller view 3

app.controller('videolistcontroller', function($scope){  alert("userid: "+$scope.userid);                 }); 

the value of $scope.userid appears 'undefined'. doing wrong?

you can use $rootscope global access in angularjs

take @ this

app.controller('logincontroller', function ($scope,$rootscope,$location){     $scope.loginuser = function (user) {         $rootscope.userid = "userid";        $location.path('/view3');     } });  app.controller('videolistcontroller', function($scope, $rootscope){  alert("userid: "+$rootscope.userid);                 }); 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -