2016-07-21 5 views
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> 
+0

コンポーネント名が要素と一致しません – charlietfl

答えて

1

誰でも、私は正しいスコープにアクセスするために$ctrlの代わりに$parentを使用して終了しました。ハッキー地獄として、それは動作します。

関連する問題