简体   繁体   English

角度组件更换功能

[英]angular component replacement feature

I am trying to use the angular component replacement feature. 我正在尝试使用角度组件更换功能。

<ul>
  <li></li>
  <li class="com"></li>
  <li class="com"></li>
</ul>

For complicated interface, if I want to make the middle .com "li" into a whole new component, and write this code like: 对于复杂的界面,如果我想将中间的.com “ li”变成一个全新的组件,并编写如下代码:

<ul>
  <li></li>
  <com-component></com-component>
</ul>

How can I make sure that the finally compiled html is exactly what the original html template looks like? 如何确定最终编译的html正是原始html模板的外观?

It is not possible as far as I have searched from angular docs . 根据我从angular docs搜索的结果,这是不可能的。

In angularjs , there is replacement feature. angularjs ,有replacement功能。 For a "compiled" angular framework, this is bit of off-putting not to have this. 对于“已编译”的角度框架,这有点不合时宜。

View Encapsulation is what you need as you want the styles to bleed in from the parent component to the child component. 您需要View Encapsulation,因为您希望样式从父组件流到子组件。

ViewEncapsulation.None - No Shadow DOM at all. ViewEncapsulation.None-完全没有Shadow DOM。 Therefore, also no style encapsulation. 因此,也没有样式封装。 ViewEncapsulation.Emulated - No Shadow DOM but style encapsulation emulation. ViewEncapsulation.Emulated-没有Shadow DOM,而是样式封装仿真。 ViewEncapsulation.Native - Native Shadow DOM with all it's goodness. ViewEncapsulation.Native-具有所有优点的本机Shadow DOM。

More on View Encapsulation 有关视图封装的更多信息

You can use an attribute selector in the com-component . 您可以在com-component使用属性选择器。

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

And then, in the template, simply add com-component as an attribute to the li element instead of adding it as a new tag. 然后,在模板中,只需将com-component作为属性添加到li元素中,而不是将其添加为新标签。

<ul>
  <li></li>
  <li com-component></li>
</ul>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 角度延迟加载:路由到特定要素组件 - Angular lazy loading: route to a specific feature component 角要素路由模块-未加载子组件 - Angular feature routing module - Child component not loaded 导入 Angular 功能模块时渲染组件 - Render a Component when a Angular Feature module is imported Angular 4:使用功能模块中SharedModule中导入的模块和组件 - Angular 4: Using modules and component imported in SharedModule, in Feature modules Angular 6:功能模块之间的共享组件不起作用 - Angular 6: Sharing component between feature modules doesn't work Angular 2 找不到在我的功能模块中声明的组件 - Angular 2 can't find a component declared in my feature module 在重置密码功能中未从外部链接找到 Angular 组件 - Angular component not found from external link in reset password feature angular2 rc5 使用功能模块中的组件不起作用 - angular2 rc5 using component from feature module not working 如何在功能模型中创建指令并在应用程序组件中使用 angular - How to create directive in feature model and use in app component in angular Angular2本机| 无法解析功能模块的组件文件 - Angular2 Native | Feature module's Component files could not be resolved
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM