DOM中没有选择器标记的Angular 2组件 [英] Angular 2 component without selector tag in DOM
本文介绍了DOM中没有选择器标记的Angular 2组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要这个:
<div *ngIf="...">div 1...</div>
<div *ngIf="...">div 2...</div>
<div *ngIf="...">div 3...</div>
但我不想重复 * ngIf
,所以我用这个模板创建了我的组件< my-component>
:
But I don't wanna repeat the *ngIf
, so I created my component <my-component>
, with this template:
<div>div 1...</div>
<div>div 2...</div>
<div>div 3...</div>
我把* ngIf放在我的组件标签中:< my-component * ngIf =...>
And I put *ngIf in my component tag: <my-component *ngIf="...">
问题是Angular 2正在放置< my DOM中的组件>
标签,我不想要它。
The problem is that Angular 2 is putting the <my-component>
tag in the DOM, and I don't want it.
对于任何了解ASP.NET WebForms的人,我想要一个Angular 2中的组件,其工作方式类似于< asp:PlaceHolder>
控制...
For anyone who knows ASP.NET WebForms, I want a component in Angular 2 that works like <asp:PlaceHolder>
control...
推荐答案
使用等效的扩展 * ngIf
符号模板
标记:
<template [ngIf]="check">
<div>div 1...</div>
<div>div 2...</div>
<div>div 3...</div>
</template>
这篇关于DOM中没有选择器标记的Angular 2组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文