为什么此transcluded
指令会重复 Name inside directive = Frank
两次?
我以为我理解了翻译,但这让我很困惑。
<div ng-app="myApp" ng-controller="myController">
<my-directive>Name in outer controller scope = {{name}}<my-directive/>
</div>
var app = angular.module("myApp", []);
app.controller("myController", function ($scope) {
$scope.name = 'George';
});
app.directive("myDirective", function () {
return {
restrict: 'E',
scope: {},
transclude: true,
template: '<div ng-transclude></div>' +
'<span>Name inside directive = {{name}}</span>',
link: function (scope) {
scope.name = 'Frank'
}
};
});
答案 0 :(得分:0)
只是因为你没有正确关闭你的标签
</my-directive>
代替<my-directive/>
答案 1 :(得分:0)
这是一个错字:
<my-directive>Name in outer controller scope = {{name}}</my-directive>