我想要这个:
<div *ngIf="...">div 1...</div>
<div *ngIf="...">div 2...</div>
<div *ngIf="...">div 3...</div>
但我不想重复 *ngIf
,所以我创建了我的组件 <my-component>
, 使用此模板:
<div>div 1...</div>
<div>div 2...</div>
<div>div 3...</div>
然后我将 *ngIf 放在我的组件标签中:<my-component *ngIf="...">
问题是 Angular 2 将 <my-component>
DOM 中的标记,我不想要它。
对于了解 ASP.NET WebForms 的任何人,我想要 Angular 2 中的一个组件,其工作方式类似于 <asp:PlaceHolder>
控制...
最佳答案
To answer your question, you can also do this...
@Component({
selector: '[my-component]'...
<my-component *ngIf="..."</my-component>
// becomes this in the dom
<div my-component _nghost...>
There is also ng-container for this purpose.
<ng-container *ngIf="something.is.there">
<div class="here">
Hello
</div>
</ng-container>
// DOM: => <div class="here">Hello</div>
关于javascript - DOM 中没有选择器标记的 Angular 2 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38287224/