LeCoupa / awesome-cheatsheets

👩‍💻👨‍💻 Awesome cheatsheets for popular programming languages, frameworks and development tools. They include everything you should know in one single file.

Home Page:https://lecoupa.github.io/awesome-cheatsheets/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Angular] Incorrect syntax for ngSwitchCase

PhiLhoSoft opened this issue · comments

Seen:

// Conditionally swaps the contents of the div by selecting one of the embedded templates based on 
// the current value of conditionExpression.
// <div [ngSwitch]="conditionExpression">
// <ng-template [ngSwitchCase]="case1Exp">...</ng-template>
// <ng-template ngSwitchCase="case2LiteralString">...</ng-template>
// <ng-template ngSwitchDefault>...</ng-template>
// </div>  

At:

// Conditionally swaps the contents of the div by selecting one of the embedded templates based on

Should be:

// Conditionally swaps the contents of the div by selecting one of the containers based on 
// the current value of conditionExpression.
// <div [ngSwitch]="conditionExpression">
//   <ng-container *ngSwitchCase="case1Exp">...</ng-container>
//   <ng-container *ngSwitchCase="'case2LiteralString'">...</ng-container>
//   <ng-container *ngSwitchDefault>...</ng-container>
// </div>  

I also replaced templates with containers (but could be real HTML tags) because using templates this way seems odd.

OK, this is actually in the cheatsheet, but it is odd, I never saw it used this way. I should try and see if the syntax is still valid or obsolete for a long time.

OK, it works, but only with templates. I learned something today… 🙂
I never saw it used this way, the alternative syntax I gave is way more used (as it can be used on real elements), and given as example in the documentation.
I will just close this issue.