AngularJS ng-switch指令与示例
html代码:
<body ng-app="AngularswitchApp">
<div ng-controller="ngswitchctrl">
Select Item:
<select ng-model="selectval" ng-options="item for item in items"></select>
<div ng-switch ="selectval">
<div ng-switch-when="one"><b>DIV1</b>: You Selected value one</div>
<div ng-switch-when="two"><b>DIV2</b>: You Selected value two</div>
<div ng-switch-when="three"><b>DIV3</b>: You Selected value three</div>
<div ng-switch-default>You are in default switch case.</div>
</div>
</div>
</body>
JavaScript代码:
<script>
var app = angular.module("AngularswitchApp", []);
app.controller("ngswitchctrl", function ($scope) {
$scope.items = ['one', 'two', 'three', 'four'];
$scope.selectval = "one";
});
</script>