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

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -