これは、angular doc about からのものng-initです。
ngInit ディレクティブを使用すると、現在のスコープで式を評価できます。
しかし、ng-initカスタム ディレクティブと一緒に使用し、ディレクティブが異なるスコープ定義を使用する場合、変数 by のng-initスコープは異なります。
<body ng-app="transcludeScope" ng-init="test='test'">
<div truescope ng-init="test2='test2'">Transcluded:<p>test: {{test}}</p><p>test2: {{test2}}</p><p>test3: {{test3}}</p></div>
<hr>
<div isolatescope ng-init="test3='test3'">Transcluded:<p>test: {{test}}</p><p>test2: {{test2}}</p><p>test3: {{test3}}</p></div>
</div>
</body>
angular.module('transcludeScope', [])
.directive('truescope', function() {
return {
transclude: true,
scope: true,
template: "<p>test: {{test}}</p><p>test2: {{test2}}</p><div ng-transclude></div>"
}
})
.directive('isolatescope', function() {
return {
transclude: true,
scope: {},
template: "<p>test: {{test}}</p><p>test3: {{test3}}</p><div ng-transclude></div>"
}
});
結果から、test2ディレクティブ内でのみ使用できtest3ますが、アプリ全体で使用できます。
誰かが彼らの行動を説明できますか? ありがとう :-)