Angular 2隐形组件容器

前端之家收集整理的这篇文章主要介绍了Angular 2隐形组件容器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
像< app-root>< / app-root>这样的容器可以打破css布局,特别是如果使用flexBox.

是否可以使用隐形组件容器?我尝试了选择器:'[app-root]’已经包含以下标签,但它们都创建了一个dom元素:

<template>,<ng-template>,<ng-container>

如果确实需要这个容器,那么如果Angular只呈现HTML注释会很棒.

解决方法

就个人而言,我认为最好的方法是使用选择器作为属性.例如,你有@Component这样:

...
@Component({
    selector: '[your-component]'
})
...

这样,your-component就是一个属性,您可以这样使用:

<div your-component>Some content...</div>

在这种情况下,您可以保证样式不会破坏.

附:据我所知,这个特性(在Angular 1中替换)在Angular 1中被弃用了,所以它不是你对Angular 2的期望.

猜你在找的Angularjs相关文章