Questions tagged [ng-switch]

The ngSwitch directive is used to conditionally swap DOM structure on your template based on a scope expression. Elements within ngSwitch but without ngSwitchWhen or ngSwitchDefault directives will be preserved at the location as specified in the template.

Usage

<ANY ng-switch="expression">
  <ANY ng-switch-when="matchValue1">...</ANY>
  <ANY ng-switch-when="matchValue2">...</ANY>
  <ANY ng-switch-default>...</ANY>
</ANY>
197 questions
61
votes
7 answers

angularjs: multiple values in a ng-switch-when

I have the following ngSwitch:

Wrong Correct

As you can see, I have the text Wrong for two options wrong and…
Jeanluca Scaljeri
  • 26,343
  • 56
  • 205
  • 333
58
votes
3 answers

Angular 2 ngSwitchCase, OR operator not working

I have multiple switch statement but for some case i need the common case. So, i am trying the OR operator => || Example: Code A
PaladiN
  • 4,625
  • 8
  • 41
  • 66
47
votes
3 answers

angularjs - ng-switch does not bind ng-model

I have this repro http://embed.plnkr.co/nVCmukG5abpi1Y4ZHkrq that show when I click 'Title3' and enter a value in text box although the entered value shows reflected in the UI, when I click the 'click' button nothing is binded for the scope…
user1791567
  • 1,388
  • 1
  • 16
  • 29
36
votes
5 answers

AngularJS: ng-switch-when with an OR

Is it possible to have an OR in ng-switch-when?
sup
If not, how could the above be…
Pavel
  • 5,320
  • 8
  • 35
  • 45
31
votes
2 answers

Angular.js ng-switch-when not working with dynamic data?

I'm trying to get Angular to generate a CSS slider based on my data. I know that the data is there and am able to generate it for the buttons, but the code won't populate the ng-switch-when for some reason. When I inspect the code, I see this twice…
user1855009
  • 971
  • 3
  • 13
  • 26
17
votes
8 answers

ng-if, not equal to?

I have a simple ng-reapt that displays a list of values.. On some of the outputs, i have a couple of ng-if to show/hide DIVs. HTML:

{{ details.Name }}

{{ details.DOB }}

17
votes
5 answers

Angular ng-switch with boolean

I want to check boolean data with angular ng-switch this is my code. but it is not working

NEW

Isuru
  • 530
  • 3
  • 9
  • 25
14
votes
1 answer

"ng-switch on" and "ng-switch" difference

I was studiously reading the AngularJS API reference for the ngSwitch directive when I came to that part : place an expression on the on="..." attribute (or the ng-switch="..." attribute) So of course I was wondering why there are two ways to…
Brain Up
  • 163
  • 2
  • 10
13
votes
3 answers

Different between *ngIf vs [ngSwitch] in Angular 2+

What are the differences between [ngSwitch] and a bunch of *ngIfs. Any performance factors we should be concerned about? *ngIf
Keep calm and pretend it's not Monday.
...
Manoj Shrestha
  • 4,246
  • 5
  • 47
  • 67
13
votes
1 answer

ngSwitch does not work with string

I'm trying to get ngSwitch to dynamically show and hide component, however ngSwitch does not seem to be working. I've created a simplifed version of this issue with this plunker This is the component Html:
johnny 5
  • 19,893
  • 50
  • 121
  • 195
12
votes
3 answers

Using html templates in angular's ng-switch

Im making an 'interactive menu' that moves along with user clicks. Im wondering if there is a way to include html templates in ng-switch, since all the logic is different in each 'switch' - it will result in huge html files.
Nitsan Baleli
  • 5,393
  • 3
  • 30
  • 52
12
votes
1 answer

ng-switch and ng-repeat on the same element interfearing

I encountered behaviour in Angular I did not expect and the purpose of this post is to find out whether this is a bug or intended and possibly an explanation why it is intended. First see this Plunkr: http://plnkr.co/edit/CB7k9r?p=preview . In the…
Kevin
  • 133
  • 1
  • 1
  • 5
11
votes
1 answer

Can't bind to 'ngSwitchDefault' since it isn't a known property of 'ng-template'

I get the error: Can't bind to 'ngSwitchDefault' since it isn't a known property of 'ng-template' Before I go on: this is not a duplicate of Angular2 - "Can't bind to 'ngSwitchWhen' since it isn't a known property of 'template'." The…
Tobias Gassmann
  • 11,399
  • 15
  • 58
  • 92
11
votes
1 answer

ng-switch in Angular2

I am playing around with angular 2 (currently with version alpha 26). ng-for and ng-if for example are working fine. I do however have problems with ng-switch. I just can't get it to work, i.e. nothing is printed. It seems as if the whole template…
PzYon
  • 2,963
  • 3
  • 16
  • 27
9
votes
1 answer

Is it possible to animate Angular 2's ng-switch

Is it possible to animate this at all? I have this block of code div([ngSwitch]="switchState") ul(fxLayout="row", fxLayoutAlign="space-between", *ngSwitchCase="0") some-list ul(fxLayout="row", fxLayoutAlign="space-between",…
1
2 3
13 14