2016-06-09 69 views
1

我需要为我的Childcomponent使用名称选择器(div) 问题在我的parentComponent中我有很多标记(DIV) 所以我需要一个技巧来识别我的div childComponent) (因为我需要的时候我用另一个名称(默认为做DIV一些阻力&下降)我不能使用它)的Angular 2使用标签Div作为组件的选择器

@Component({ 
    selector: 'div', 
    template: `<div [innerHTML]="content"></div>`, 

}) 
export class ChildComponent { 
    @Input() content:string=''; 
    } 

,并鉴于我的父母的HTML我把这个

<div [content]="value"> 

回答

0

不知道我理解的问题,但你可以在content属性添加到选择:

@Component({ 
    selector: 'div[content]', 
    template: `<div [innerHTML]="content"></div>`, 

}) 
export class ChildComponent { 
    @Input() content:string=''; 
} 

,然后使用它像

<div [content]="value"> 

Plunker example

+0

增加了Plunker –

+0

我会显然有很多我的html页面中的标签div 我需要识别我从ChildComponent 带来的标签div,以便该div将有特殊的显示 我需要th ChildComponent的e div有一个wysiwyg 和其他div保持正常 –

+0

对不起,我不明白你的意见。 “ChildComponent”仅适用于具有“内容”属性的元素。我的建议解决方案无法按预期工作。期望的行为是什么? –