如何删除/ HTML从更换angular2组件的选择标签 [英] How to remove/replace the angular2 component's selector tag from HTML

查看:183
本文介绍了如何删除/ HTML从更换angular2组件的选择标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用的angular2(版本2.0.0-alpha.46),我创建几个组件,当创建与下面code中的angular2组件

I am getting started with the angular2 (version 2.0.0-alpha.46), I am creating few components, When creating the angular2 component with the below code

打字稿

import {ComponentMetadata as Component, ViewMetadata as View} from 'angular2/angular2';

@Component({
   selector: 'my-component'
})

@View({
     template: '<div class="myClass">Hello My component</div>'
 })

export class MyCompoent{
    constructor() {
        console.info('My Component Mounted Successfully');
    }
}

HTML

<my-component></my-component>

它工作正常,但是当我做检查的元素,我可以看到像

It works fine, but when i do a inspect element, i can see a tag generated like

输出HTML

<my-component>
    <div>Hello My component</div>
<my-component>

问题

它使&LT;我-成分&gt;在HTML 标签,还有一些我的CSS都没有按预期工作

it keeps the <my-component> tag in the HTML, and some of my CSS are not working as expected.

所以是他们的方式来删除标记&LT;我-成分&gt; ?类似于角的1.x(更换:在指令真)

So is their a way to remove the tag <my-component> ? similar to angular 1.x (replace: true in the directive).

任何帮助将是AP preciated ..!

Any help would be appreciated..!

推荐答案

根据的 https://github.com/angular/angular/issues/3866 因为它似乎不是一个好主意。

Replace was deprecated in 1.0 according to https://github.com/angular/angular/issues/3866 because it seemed to not be a good idea.

作为一种变通方法,您可以像

As a workaround you can use a selector in your component like

[myComponent]

,然后使用它像

<div myComponent>Hello My component</div>

[我组分] ,然后使用它像&LT; D​​IV我-成分&gt;你好我组分LT; / DIV&GT; ,但据我所知驼峰现在美元Angular2 pferred p $。

or [my-component] and then use it like <div my-component>Hello My component</div> but AFAIk camelCase is now preferred in Angular2.

这篇关于如何删除/ HTML从更换angular2组件的选择标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆