Angularjs 在角度分量中使用transcludeFn
我不能自定义角度分量中的转换(角度1.5),这是真的吗?我想解决的任务是使用转换将模板传递给组件,并使其能够使用“组件中”变量。像这样:Angularjs 在角度分量中使用transcludeFn,angularjs,Angularjs,我不能自定义角度分量中的转换(角度1.5),这是真的吗?我想解决的任务是使用转换将模板传递给组件,并使其能够使用“组件中”变量。像这样: <my-items-component items="$ctrl.items"> <div>{{::item.description}}</div> </my-items-component> {{::item.description} 项目应该放在my items组件文档中,并用于自定义组件内部的
<my-items-component items="$ctrl.items">
<div>{{::item.description}}</div>
</my-items-component>
{{::item.description}
项目应该放在my items组件文档中,并用于自定义组件内部的项目表示
我可以通过指令,使用transcludeFn函数来实现这一点,但似乎并没有参数传递给$postLink组件钩子
所以,我应该为此使用指令还是有其他方法?要在AngularJS 1.5组件中使用tansclusion,您需要首先使用
transclude:true
在组件模板中启用tarnsclusion,然后使用
我创建了一个示例笔有两种方法可以解决您的问题
app.component('myItemComponent', new myItemComponentConfig());
function myItemComponentConfig() {
this.controller = componentController;
this.template = '<div>{{::item.description}}</div>',
this.bindings = {
this.bindings = {
items:'<'
}
};
this.require = {};
}
app.component('myItemComponent',新的myItemComponentConfig());
函数myItemComponentConfig(){
this.controller=组件控制器;
this.template='{{::item.description}}',
此文件的绑定={
此文件的绑定={
条目:“我找到了答案
这解决了我的问题。我的例子是:
<my-custom-component>
<input model="$parent.$ctrl.name">
</my-custom-component>
然后,在我的组件中,我现在有了“name”。我希望这对您有所帮助。我知道如何使用transclusion。我需要使用自定义transclusion(将转置的内容绑定到另一个作用域)。我以前在指令链接函数中使用过transcludeFn。使用jsbin或plunker来尝试使用transcludeFn怎么样?
app.component('myItemComponent', new myItemComponentConfig());
function myItemComponentConfig() {
this.controller = componentController;
this.template = '<div></div>',
this.bindings = {
items:'<'
};
this.require = {};
this.transclude:true;
}
<my-items-component items="$ctrl.items">
<div>{{::item.description}}</div>
</my-items-component>
<my-custom-component>
<input model="$parent.$ctrl.name">
</my-custom-component>