NG Switch Test
by rgthree
HTML
<div ng-app="app" ng-controller='AppCtrl'>
<ul ng-switch="mode">
<one ng-switch-when="1"></one>
<two ng-switch-when="2">2</two>
</ul>
<ul>
<one ng-show="mode === 1"></one>
<two ng-show="mode === 2">2</two>
</ul>
<button ng-click="toggle()">Toggle</button>
</div>
JavaScript
var app = angular.module('app', []);
app.controller('AppCtrl', function ($scope) {
$scope.mode = 1;
$scope.toggle = function() {
$scope.mode = $scope.mode === 2 ? 1 : 2;
}
});
var OneCtrl = function() {
this.text = +(new Date());
};
app.directive('one', function() {
return {
template: '<ul>{{oneCtrl.text}}</ul>',
restrict: 'E',
replace: true,
scope: {},
controller: OneCtrl,
controllerAs: 'oneCtrl',
};
})