Angularjs Examples

AJS Examples

AngularJS ng-Switch Directive

The AngularJS ng-switch directive is used to chooses one of the element and makes it visible based on the expression.


<div ng-switch on="variable">
    <div ng-switch-when="value1">
        <h1>Show Div1</h1>
    <div ng-switch-when="value2">
        <h1>Show Div2</h1>
    <div ng-switch-default>
        <h1>Show Default Div</h1>

AngularJS ng-Switch Directive Example

<title>My first AngularJS code</title>
<Script SRC="">
<div ng-app ng-init="page=one">
    <li><a href="#" ng-click="page='one'">Page One</a></li>
    <li><a href="#" ng-click="page='two'">Page Two</a></li>

<div ng-switch on="page">
    <div ng-switch-when="one">
        <h1>Page One</h1>
    <div ng-switch-when="two">
        <h1>Page Two</h1>
    <div ng-switch-default>
        <h1>Page Default</h1>

See Live Example