DOM中没有选择器标签的Angular 2组件 [英] Angular 2 component without selector tag in DOM
问题描述
我想要这个:
div 1...<div *ngIf="...">div 2...</div><div *ngIf="...">div 3...</div>
但我不想重复*ngIf
,所以我用这个模板创建了我的组件
:
div 1...<div>div 2...</div><div>div 3...</div>
我把 *ngIf 放在我的组件标签中:<my-component *ngIf="...">
问题是 Angular 2 将
标签放在 DOM 中,而我不想要它.
对于任何了解 ASP.NET WebForms 的人,我想要一个 Angular 2 中的组件,它的工作原理类似于 <asp:PlaceHolder>
控件...
使用等效的 扩展了 *ngIf
符号,带有 template
标签:
<div>div 1...</div><div>div 2...</div><div>div 3...</div>模板>
I want this:
<div *ngIf="...">div 1...</div>
<div *ngIf="...">div 2...</div>
<div *ngIf="...">div 3...</div>
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>
And I put *ngIf in my component tag: <my-component *ngIf="...">
The problem is that Angular 2 is putting the <my-component>
tag in the DOM, and I don't want it.
For anyone who knows ASP.NET WebForms, I want a component in Angular 2 that works like <asp:PlaceHolder>
control...
Use equivalent expanded *ngIf
notation with template
tag:
<template [ngIf]="check">
<div>div 1...</div>
<div>div 2...</div>
<div>div 3...</div>
</template>
这篇关于DOM中没有选择器标签的Angular 2组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!