小编Tre*_*ent的帖子

如何在组件视图中访问rootscope

我有角度控制器仪表板并在仪表板中设置根范围值并使用范围访问仪表板模板内部组件中的根范围值.但我不知道这是否正确..我无法得到值

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);
Run Code Online (Sandbox Code Playgroud)

我没有定义

html scope view angularjs rootscope

7
推荐指数
1
解决办法
5056
查看次数

标签 统计

angularjs ×1

html ×1

rootscope ×1

scope ×1

view ×1