我有角度控制器仪表板并在仪表板中设置根范围值并使用范围访问仪表板模板内部组件中的根范围值.但我不知道这是否正确..我无法得到值
- 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,$timeout,$http,$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);
我没有定义
解决方法
从模板中,您可以通过$root.varName访问rootscope变量