ng2如何在渲染时去掉自定义标签层

0

页面那么多自定义标签真的好么?怎么设置在渲染时去掉自定义标签层?还有如果是自定义标签,能设置样式吗?

  • 0
    ciga 113个月前 回答

    1. 对于大多数浏览器,它不认识的标签会被默认的当做span标签处理,因此你可以正常的设置样式

    2. Angular 2 不能像版本1里那样将自定义标签替换掉:

    参考官方文档:

    Directives that replace their host element (replace: true directives in Angular 1) are not supported in Angular 2. In many cases these directives can be upgraded over to regular component directives.

    可以在定义组件时将选择符设置为属性选择符,例如:

    @Component({
        selector: "[ezComponent]",
        template: "<h1>...</h1>"
    })
    class EzComponent{...}

    这样你可以得到一个相对干净的DOM树:

    <div ezComponent>
        <h1>...</h1>
    </div>