2

I'm using a switch to conditionally include different content. I want the inner content (e.g. welcome directive) to replace the parent ng-switch element. I know that you can do this with custom directives using the replace=true configuration property, but is this possible to do with built in directives such as ng-switch?

<div id="container">
    <ng-switch on="tabIndex">

        <welcome ng-switch-when="welcome"></welcome>

        <main ng-switch-when="main"></main>

        <help ng-switch-when="help"></help>

    </ng-switch>
</div>

For example, When the value of tabIndex is 'help', I want the following html to result:

<div id="container">

    <help><!-- contents of help template --></help>

</div>
1
  • 1
    I think its not possible with just the ng-switch directive. It just appends the correct switch-when to its main element.
    – Oliver
    Jun 5, 2013 at 13:12

1 Answer 1

8

You'll always need the logic there, but you don't have to use an element for a switch. It'll work just as well as an attribute on the parent:

<div id="container" ng-switch on="tabIndex">
    <welcome ng-switch-when="welcome"></welcome>
    <main ng-switch-when="main"></main>
    <help ng-switch-when="help"></help>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.