Я не могу получить доступ к привязке рамки $ctrl
нового angular.component()
при использовании ng-transclude
.
Я хочу получить доступ к $ctrl
вместо объекта .controller()
на странице, так как мы хотим перейти на угловую2 вниз по дорожке.
Здесь показан демонстрационный пример: https://plnkr.co/edit/M4k7Av8Q2OrMSsvhZjsb?p=preview
Надеюсь, кто-то может пролить свет! Код ниже:
// 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>
Любой, у кого есть такая же проблема, я просто закончил использование $parent
вместо $ctrl
для доступа к правильной области. Хакер, черт возьми, но он работает.