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
4
votes
1 answer

Angular2 (2.0.0-beta.17) NgSwitchWhen gives "No provider for TemplateRef!"

I've been stumped by this for a fair few hours now. It's time for one of you guys to tell me what I'm doing wrong :) The below component fails with 'No provider for TemplateRef!'. A plunker is available here. I got the ngSwitch syntax from…
LOAS
  • 7,161
  • 2
  • 28
  • 25
4
votes
1 answer

AngularJS $index inside ng-switch

I am trying to access $index of ng-repeat and place it inside ng-switch-when. Here is the last thing I have tried. Small piece of what I am trying to do:
  • Honchar Denys
    • 1,408
    • 4
    • 29
    • 54
  • 4
    votes
    1 answer

    Angular JS: using ng-switch and checking if file exists

    i am looping through a list of things, and if a thing has an image i want to show it. but if a thing does not have an image, i want to display default text:
    SeanPlusPlus
    • 8,663
    • 18
    • 59
    • 84
    4
    votes
    1 answer

    How to prevent controller reloading when using ng-switch

    In this example, using ng-switch, I'm able to switch between different views. Each view is assigned a controller. I've put a quick sample online here : http://jsfiddle.net/FBHjZ/1/ It looks like the controller is reinstanciated everytime I switch…
    Florian F
    • 8,822
    • 4
    • 37
    • 50
    3
    votes
    5 answers

    Change img [src] specifically with ngSwitch

    I want to change img tag src based on a condition. I am using ternary operator right now; I want to ask is there a way to use ngSwitch instead (WITHOUT REPEATING the img tag). Here is my code:
    3
    votes
    6 answers

    ngSwitch is "Attribute Directive" OR "Structural Directive" ?

    I am a bit confused regarding ngSwitch directive -- whether it is 'attribute directive' or 'structural directive'. Attribute directives are written with 'square brackets' like [ngStyle], [ngClass], etc. (and we write it as [ngSwitch] which refers…
    Deadpool
    • 7,811
    • 9
    • 44
    • 88
    3
    votes
    1 answer

    ngSwitch not showing item when evaluated to true

    I'm not sure what I'm doing here. I have this ngSwitch inside ngFor
  • Tomasz Golinski
    • 743
    • 5
    • 25
  • 3
    votes
    1 answer

    How to get a reference to the component after ngSwitchCase in Angular 2?

    With the following html:
    user1589188
    • 5,316
    • 17
    • 67
    • 130
    3
    votes
    2 answers

    ngSwitch inside of ngFor angular 2+

    I am moving an old angular 1 application to angular 2+ and need to display elements of array B when elements of array A = a known value.
    may19c19
    • 360
    • 1
    • 4
    • 15
    3
    votes
    2 answers

    ng-switch with typeof expression

    So I have a variable which could be of any type. By type I mean it could be a string, or an object. I'm trying to run different code depending on the type. My variable is named range, it's defined in the JavaScript. What I've tried is. vars is an…
    Downgoat
    • 13,771
    • 5
    • 46
    • 69
    3
    votes
    1 answer

    ngModel with ngSwitch, cannot watch string variables?

    I am having trouble with using $scope.$watch on some angular variables that I have in the scope of my project. I've made a sample jsfiddle to illustrate the issue. Basically, I can $scope.$watch any model within the ng-switch as long as it is an…
    3
    votes
    1 answer

    ng-switch-when: Does it recreate new controller each time and remove previous data when selecting different step?

    I have a single page webapp based on angular.js And seems like I have performance problems. so I have the main controller and view for it which looks like this
    Ph0en1x
    • 9,943
    • 8
    • 48
    • 97
    3
    votes
    2 answers

    Use links to change ng-switch

    How would I use links to trigger an ng-switch? My current html:
    2
    votes
    0 answers

    Cannot render another component within an Angular Material dialog/modal

    I'm using Material design components for my Angular application. For a few parts of my application, I'm opening a dialog/modal that covers the whole viewport and I want to nest components within that modal. For example, here is the code to open a…
    Dave Guerrero
    • 93
    • 1
    • 10
    2
    votes
    2 answers

    Angular 5 - ngSwitch & ngSwitchCase not to be on real element of html

    I am trying to create different html table content based on component field type properties. My concerns is as i am manipulating html table i cannot insert any extra div inside my tbody hence using ng-template to cover this case but i am getting…
    Feroz Siddiqui
    • 3,840
    • 6
    • 34
    • 69
    1 2
    3
    13 14