Add a shorter alias for ng-container
See original GitHub issueWhich @angular/* package(s) are relevant/releated to the feature request?
core
Description
ng-container tends to be used a lot. Especially if you don’t want erroneous elements appearing in your html that are there only because of some conditional checks. This becomes verbose. Perhaps we can have a short alias for ng-container?
We already have short forms for the template with things with ngFor / ngForOf etc.
E.g. This is a an OTT example to highlight some common use cases
<ng-container *ngIf="...">
<ng-container *ngFor="...">
<ng-container [ngSwitch]="...">
<ng-container *ngSwitchCase="'...'">
...
</ng-container>
<ng-container *ngSwitchCase="'...'">
...
</ng-container>
<ng-container *ngSwitchCase="'...'">
...
</ng-container>
</ng-container>
</ng-container>
</ng-container>
Proposed solution
I would love to see a short alias for the container like
<ng *ngIf="...">
<ng *ngFor="...">
<ng [ngSwitch]="...">
<ng *ngSwitchCase="'...'">
...
</ng>
<ng *ngSwitchCase="'...'">
...
</ng>
<ng *ngSwitchCase="'...'">
...
</ng>
</ng>
</ng>
</ng>
Alternatives considered
Containers could be marked implicitly using an unnamed asterisk attribute
<ng-for *="value of values">
<ng-if *="value">
Show something
</ng-if>
</ng-for>
OR
<ngFor *="value of values">
<ngIf *="value">
Show something
</ngIf>
</ngFor>
Or perhaps a different shorter element name other than <ng …?
EDIT 1: add some clarification EDIT 2: removed bad alternative, add some more context EDIT 3: update alternative with suggestion from @stupidawesome below EDIT 4: added another alternative that doesn’t dash-case the selector
Issue Analytics
- State:
- Created 2 years ago
- Reactions:39
- Comments:33 (16 by maintainers)
Top GitHub Comments
I know that the voting process doesn’t actually include “thumb downs”, but I’ll just explain my vote:
@C
instead of@Component
etc.I would go further than shorthand and propose an empty tag mayby? Why? - Because it’s even shorter and <ng-container> is an element does not end up in DOM anyway