angularJS学习之路(八)---ng-switch

时间:2022-06-25
本文章向大家介绍angularJS学习之路(八)---ng-switch,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

这个指令   和  ng-switch-when 以及  on="name"一起使用    

在name值发生变化时渲染不同的指令到视图中   

例子:

<!DOCTYPE html>
<html ng-app="myApp">

	<head>
		<meta charset="utf-8">
		<title></title>
	</head>

	<body>

		<div ng-controller="SomeController" ng-switch on="person.name">
			<input type="text" ng-model="person.name" />
			<p ng-switch-default>And the winner is</p>
			<h1 ng-switch-when="Erik">{{ person.name }}</h1>
		</div>

		<script type="text/javascript" src="../js/angular.min.js"></script>
		<script>
			var app = angular.module('myApp', []);
			app.controller('SomeController', function($scope) {
				$scope.person = {};
			});
		</script>
	</body>

</html>

ng-switch-default  输出默认值