これが私のスクリプトです:
angular.module('MyApp',[])
.directive('mySalutation',function(){
return {
restrict:'E',
scope:true,
replace:true,
transclude:true,
template:'<div>Hello<div ng-transclude></div></div>',
link:function($scope,$element,$attrs){
}
};
})
.controller('SalutationController',['$scope',function($scope){
$scope.target = "StackOverflow";
}])
そしてhtml:
<body ng-app="MyApp">
<my-salutation ng-controller="SalutationController">
<strong>{{target}}</strong>
</my-salutation>
</body>
問題は、ディレクティブにSalutationController
適用されると、トランスクルードされた要素には表示されないことです。しかし、要素を配置または配置すると、機能します。ドキュメントが言うように、新しいスコープを作成します。my-salutation
$scope.target
ng-controller
<body>
<strong>
ng-controller
この場合、そのスコープとディレクティブのスコープがどのように互いに干渉しているのか、誰が説明できますか?
コントローラーをディレクティブに配置するにはどうすればよいですか? ヒントをいただければ幸いです。