How to access the root element in component view

I have an angular control panel and set the root area value in the control panel and access this root area value in the component inside the control panel template using the area ... but I don’t know if it is right or not .. and I can’t get this value

function DashBoardController($http, $window, $rootScope, apiurl, $scope, $location,$interval) { var ctrl = this; ctrl.$onInit = function () { getUser(); }; function getUser(){ $http({ method: 'GET', url: apiurl + '/getUser', }).success(function (data, status) { if (data.status == true) { $rootScope.user = data.result; $rootScope.test = "TEST"; } }); } function Controller1($rootScope,$scope, $timeout,$http, apiurl,$interval) { var ctrl = this; $scope.value = $rootScope.test; alert($scope.value); $scope.value1 = $rootScope.user; console.log($scope.value1); } app.module('app').component('component1', { templateUrl: '../resources/views/component/component1.html', controller: Controller1 }); })(window.angular); 

am get undefined

+5
source share
1 answer

From the template, you can access the root variables through $root.varName

+4
source

Source: https://habr.com/ru/post/1258314/


All Articles