![](/img/trans.png)
[英]Angular how to generate dynamically component without the selector tag
[英]Angular 2 use tag Div as selector for component
我需要使用我的Childcomponent作为名称选择器(div),问题在我的parentComponent中我有很多标签(DIV)所以我需要一个技巧来识别我的div(of childComponent)(因为我需要在div上做一些拖放操作我用另一个名字(默认)我不能用它)
@Component({
selector: 'div',
template: `<div [innerHTML]="content"></div>`,
})
export class ChildComponent {
@Input() content:string='';
}
并在视图我的父母的HTML我把它
<div [content]="value">
我不确定我是否理解了这个问题,但您可以将content
属性添加到选择器:
@Component({
selector: 'div[content]',
template: `<div [innerHTML]="content"></div>`,
})
export class ChildComponent {
@Input() content:string='';
}
然后像使用它一样
<div [content]="value">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.