ngSwitch not using the `*` syntax ?
See original GitHub issueAs ngIf
or ngFor
, ngSwitch
is manipulating the DOM.
But, unless I miss something, it can only be called using [ng-switch]
and not *ng-switch
like we do for ngIf
or ngFor
.
<div [ng-switch]="value">
<div *ng-switch-when="'1'">is 1</div>
<div *ng-switch-when="'2'">is 2</div>
<div *ng-switch-default>is another value</div>
</div>
Maybe it would make more sense to have something like:
<div *ng-switch="value">
<div *ng-switch-when="'1'">is 1</div>
<div *ng-switch-when="'2'">is 2</div>
<div *ng-switch-default>is another value</div>
</div>
which would be closer to what we do for ngIf
or ngFor
:
<div *ng-if="test">..</div>
<li *ng-for="#user of users">{{user}}</li>
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
NgIf & NgSwitch • Angular - codecraft.tv
We define the condition by passing an expression to the directive which is evaluated in the context of its host component. The syntax...
Read more >Angular2 ngSwitch not working - Stack Overflow
Your syntax for using isn't correct. It should be [ngSwitch]="switch_expression" and then the cases should look like this <some-element ...
Read more >NgSwitch - Angular
The [ngSwitch] directive on a container specifies an expression to match against. The expressions to match are provided by ngSwitchCase directives on views ......
Read more >ngSwitch, ngSwitchcase, ngSwitchDefault Angular Example
In this tutorial, we will look at the syntax of ngSwitch , ngSwitchcase & ngSwitchDefault . We will show you how to use...
Read more >Angular 8 ngSwitch Directive - Javatpoint
In Angular 8, ngSwitch is a structural directive which is used to Add/Remove DOM Element. It is similar to switch statement of C#....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Really old issue, but I have one related with this. I understand @mhevery point about not having the ngSwitch in the
<ul>
, but this is my scenario.And well, as you know, I can’t use the
[ngSwitch]
in the<template>
created for the ngFor. And can’t put it in the<ul>
since I need to switch based on some #item value. So my only option in here, is to create just one<li>
using ngClass to change a large list of classes, and then put the ngSwitchWhen in a template. But this doesn’t feel like the right way to do it.I think the better way for this, would be
instead of
or
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.