html – 如何在组件视图中访问rootscope

前端之家收集整理的这篇文章主要介绍了html – 如何在组件视图中访问rootscope前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有角度控制器仪表板并在仪表板中设置根范围值并使用范围访问仪表板模板内部组件中的根范围值.但我不知道这是否正确..我无法得到值
  1. function DashBoardController($http,$window,$rootScope,apiurl,$scope,$location,$interval) {
  2. var ctrl = this;
  3. ctrl.$onInit = function () {
  4. getUser();
  5. };
  6. function getUser(){
  7. $http({
  8. method: 'GET',url: apiurl + '/getUser',}).success(function (data,status) {
  9. if (data.status == true) {
  10. $rootScope.user = data.result;
  11. $rootScope.test = "TEST";
  12.  
  13. }
  14. });
  15. }
  16.  
  17. function Controller1($rootScope,$timeout,$http,$interval) {
  18. var ctrl = this;
  19. $scope.value = $rootScope.test;
  20. alert($scope.value);
  21. $scope.value1 = $rootScope.user;
  22. console.log($scope.value1);
  23. }
  24. app.module('app').component('component1',{
  25. templateUrl: '../resources/views/component/component1.html',controller: Controller1
  26. });
  27. })(window.angular);

我没有定义

解决方法

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

猜你在找的HTML相关文章