javascript - $rootScope is not defined -


i'm trying use cookie value in multiple places , within multiple controllers error saying $rootscope not defined

here's code:

capapp.controller('cookiectrl', ['$scope','$cookies', function($scope, $rootscope, $cookies) {   // set variable nav   $rootscope.cookieset = $cookies.user_id; }]);  capapp.controller('maincontroller', function($scope, $location) {     $scope.user_id = $rootscope.cookieset; // set global var });

is there better way this? want cookie value available site wide

you missed add $rootscope dependency in both controllers

code

capapp.controller('cookiectrl', ['$scope','$rootscope', '$cookies',    function($scope, $rootscope, $cookies) {   // set variable nav   $rootscope.cookieset = $cookies.user_id; }]);  capapp.controller('maincontroller', ['$scope', '$location', '$rootscope',    function($scope, $location, $rootscope) {     $scope.user_id = $rootscope.cookieset; // set global var }); 

ensure array annotation of dependency injection ensure won't break code while doing javascript minification.

side note:- don't use $rootscope sharing application data, use service/factory same


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -