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
2
votes
4 answers

Angular 5 ngSwitch is not working

In my application I am trying to implement navbar based on roles of user. If user is a admin it should show a different menu and for normal user it should show the menu only for the user. I am using ngSwitch to restrict the navbar but could not do…
Hasan Zubairi
  • 1,037
  • 4
  • 23
  • 57
2
votes
1 answer

How to custom sort JSON array in Typescript or Angular

How to sort JSON array in Angular? The array: {"title":"DEASDFS","Id":11}, {"title":"AASDBSC","Id":2}, {"title":"JDADKL","Id":6}, {"title":"MDASDNO","Id":3}, {"title":"GHFASDI","Id":15}, {"title":"HASDFAI","Id":1}, {"title":"ASDHFI","Id":9}, I want…
Mr world wide
  • 4,696
  • 7
  • 43
  • 97
2
votes
1 answer

Manage multiple templates in a single page in Angular

I have a use case where I need 1 view (Template) to show on screen based on a condition. Their are over 10 templates available but only one of them needs to be visible at a time. Which of the following solutions is most relevant Using ngIf over…
2
votes
3 answers

Using ng-switch with buttons

I'm trying to use ng-switch with 2 buttons in order to show HTML elements depending on which button is clicked. I have not seen any example like that here's my code so far:
Jolan
  • 681
  • 12
  • 39
2
votes
1 answer

Setting one parameter to a certain value upon entering a different parameter - NgSwitch?

I have an application in which you can add or edit values to a database. I want to make it so that when I set one parameter to anything (it is empty by default) the second parameter gets set to a specific value. Further explanation on what I'm…
ire
  • 491
  • 2
  • 12
  • 26
2
votes
0 answers

How can I show all divs at once while using ngswitchngSwitchCase?

I have the following code:
I am using the ngSwitchCase to switch between the divs depending on what…
abedzantout
  • 802
  • 4
  • 15
  • 28
2
votes
1 answer

ngSwitchCase in angular 2 instead of ngSwitchWhen

I was using ngSwitchWhen & now I want to use ngSwitchCase, I referred to the syntax here https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html & did the same in my application. There aren't any errors but it isn't working fine…
Himanshi Gupta
  • 171
  • 1
  • 2
  • 13
2
votes
2 answers

Ng-Switch not Working properly with String.length - AngularJS

I'm working on a Store application and I need to show 2 different strings based on a response. If I receive the response with no item title I need to show "No Item Title Found", else, I need to show item's title limited to a certain amount of…
AndreaM16
  • 3,917
  • 4
  • 35
  • 74
2
votes
2 answers

angular 2 ngIf and ngSwitch for simple login

If ngIf is false, the whole html block won't be rendered. Is it the same for the false cases of a ngSwitch? I want to have certain elements of a webpage not rendered unless the user is logged in. And a followup question on performance: let's say a…
Han Che
  • 8,239
  • 19
  • 70
  • 116
2
votes
1 answer

How to make Angular ng-switch animate(enter/leave) in more than one way?

I write an angular directive called 'cardViewer', which can show images inside it with animation. When you press "prev" button, image slides left. When you press "next" button, image slides right. I try to do this with ng-switch, which only supports…
2
votes
2 answers

using ng-switch and ng-repeat for a slider

I can't make this kind of slider work, taking data from the controller. This example works fine:
cor
  • 3,323
  • 25
  • 46
2
votes
2 answers

How to have if else work in ng-repeat with ng-switch?

http://plnkr.co/edit/GQ40yelDbLMpRyZqYpNB?p=preview Or any other ng In my example above I have a model containing some Bitcoin transactions, some are incoming and some outgoing, both of which have a different icon. vm.transactions = [ { type:…
Leon Gaban
  • 36,509
  • 115
  • 332
  • 529
2
votes
1 answer

ng-repeat and ng-switch doesn't work on same element

JS $scope.mode = "test" $scope.array = ['test1', 'test2', 'test3'] HTML
Test {{item}}
When I do this the above, the output I get is Test…
2
votes
2 answers

Is it possible to place the ng-switch-when attribute on multiple elements?

I'm trying to switch elements using ng-switch showing specific elements when I set a certain index. ng-switch is working, except it's only showing the last switch statement. I'm only showing the "Frame 2" div when using this code:
hitautodestruct
  • 20,081
  • 13
  • 69
  • 93