0
ng-transclude
を使用すると、angular.component()
の$ctrl
スコープバインディングにアクセスすることができません。
私たちはangular2に移行することを検討しているので、ページ上の.controller()
の代わりに$ctrl
にアクセスしたいと思います。 https://plnkr.co/edit/M4k7Av8Q2OrMSsvhZjsb?p=preview
うまくいけば、誰かがいくつかの光を当てることができます。
は、ここでこれを証明するplunkrあります!以下のコード:同じ問題を持っている
// app.js
angular.module('test.app', [])
.component('transcludedComponent', {
transclude: true,
template: '<div ng-transclude></div>',
controller: function(){
this.text = 'hello world'
}
})
.component('regularComponent', {
template: '<h2>{{$ctrl.otherText}}</h2>',
controller: function(){
this.otherText = 'this binding works';
}
});
angular.element(document.body).ready(function(){
angular.bootstrap(document, ['test.app']);
});
<!-- index.html -->
<transcluded-component>
<h2>transcluded text has no $ctrl: {{ $ctrl.text }}</h2>
<regular-component></regular-component>
</transcluded-component>
コンポーネント名が要素と一致しません – charlietfl