【发布时间】:2019-01-11 01:08:07
【问题描述】:
我不得不做一件奇怪的事情,我为此挣扎了很长时间:如何“冻结”一个嵌入的表达式以绑定在特定的 child 组件中,而不是绑定的默认行为到当前控制器?所以用这样的代码:
<parent>
<child>{{childCtrl.childValue}}</child>
</parent>
我想将表达式绑定到 child 组件的控制器以显示其数据。
组件如下所示:
.component('parent',{
template: `<p ng-transclude></p>`,
transclude: true
})
.component('child',{
template: `
<li>expression hard coded: <b>{{childCtrl.childValue}}</b>
<li>expression value from transclusion: <b><span ng-transclude></span></b>`,
transclude: true,
controllerAs: 'childCtrl',
controller: function() {
this.childValue = 'working!'
}
})
注入一些被动 HTML 没有问题,但我也确实需要使用表达式来做到这一点。 Here's the fiddle,我相信有办法的。
【问题讨论】:
标签: angularjs