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
Post a Comment