gpt4 book ai didi

html - 如何在组件 View 中访问根作用域

转载 作者:太空狗 更新时间:2023-10-29 14:44:37 25 4
gpt4 key购买 nike

我有 Angular Controller 仪表板并在仪表板中设置根范围值并使用范围访问仪表板模板内组件中的根范围值..但我不知道这是否正确..我不能获得那个值(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);

我变得不确定了

最佳答案

从模板中,您可以通过 $root.varName 访问 rootscope 变量

关于html - 如何在组件 View 中访问根作用域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40079835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com