问:
为什么导致空{{ name }}
?
Plunker:
http://plnkr.co/edit/32t8u4VL9BiuhHcC80LF?p=preview
脚本:
var app = angular.module('app', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
app.directive('portal', function() {
return {
restrict: 'E',
transclude: true,
template: '<div><span>Header</span><div ng-transclude></div><span>Footer</span></div>'
}
})
HTML:
<portal ng-app="app" ng-controller="MainCtrl">
<p>Hello {{ name }}, let's see if Angular is working at all... 1 + 2 = {{ 1 + 2 + '!' }}</p>
</portal>
可以告诉我为什么我需要这样做 - 这就是为什么你不能在同一个元素中使用ngApp和ngController的ngTransclude指令? –
不是我的头顶,但我的猜测是该指令如何与ngTransclude作用域。我个人从未在自定义指令中看到过'hg-app',因为文档建议在整个角度应用程序的父级上使用'hg-app'。 –
是的,我知道Angular的建议。只是因为我有多个命名冲突的SPA,并且角度既不提供命名空间,也不提供模块的动态加载和卸载,而且我在这些站点之间有共同的内容,所以我决定可以使用指令将每个“应用程序”和页脚。为了方便起见,我想在上述指令的同一个元素上加上'ngApp'。谢谢你的帮助! –