ngSwitch指令用於根據範圍表達式在模板上有條件地交換DOM結構。ngSwitch是和ngSwitchWhen
or ngSwitchDefault指令一塊兒使用的。
html
例子:app
index.htmlspa
<html ng-app="extendApp"> <head> <meta charset="UTF-8"> <title></title> </head> <body ng-controller="extendController"> <div> <div> <input ng-model="name" /> </div> <div ng-switch="name"> <span ng-switch-when="ms">good</span> <span ng-switch-when="family">health</span> <span ng-switch-when="future">rich</span> </div> </div> <div> {{aStatus}} </div> <script src="framework/angular.js"></script> <script src="myJs/aaa.js"></script> </body> </html>
script.jscode
angular.module("extendApp",[]) .controller("extendController",function ($scope) { $scope.name = ""; });