You may use $parent
to access isolated component scope, e.g.:
<test>
{{ $parent.$ctrl.myVar }}
</test>
.component('test', {
transclude: true,
template: '<ng-transclude></ng-transclude>',
controller: function($scope) {
var ctrl = this;
this.$onInit = function() {
ctrl.myVar = 1123;
}
}
})
Or else you may define dedicated transclusion slot:
<test>
<some-fancy-slot>
{{ $parent.$ctrl.myVar }}
</some-fancy-slot>
</test>
.component('test', {
transclude: {
slot: 'someFancySlot'
},
template: '<div ng-transclude='slot'></div>',
controller: ...
})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…