$rootScope变量在指令中未定义


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未定义?错误在哪里?

解决方案是用$root.show替换$rootScope.show。对此有什么解释吗?

最新更新