$ rootScope变量在指令内部未定义

时间:2020-05-18 16:24:52

标签: angularjs

angular.module('test', [])
.directive('microFrontEnd', function($rootScope) {
   'use strict';       
    $rootScope.show = true;
    return {
        restrict: 'E',
        templateUrl: '../template.html'
    };
});

和模板:

<div ng-show="$rootScope.show">Hello man</div>

为什么$rootScope.show未定义?错误在哪里?

1 个答案:

答案 0 :(得分:0)

解决方案是将$rootScope.show替换为$root.show。有什么解释吗?

相关问题