标签:
<p> <a href="#" ng-click="toggle()">Toggle Section</a> </p> <div ng-switch="section"> <p ng-switch-when="happy" bn-directive> Oh sweet! </p> <p ng-switch-when="sad" bn-directive> Oh noes! </p> </div>
js
var app = angular.module( "Demo", [] ); // 定义控制器 app.controller( "DemoController", function( $scope ) { $scope.section = "happy"; //在toggle函数中改变section的值,以此在标记中显示/隐藏不同的部分 $scope.toggle = function() { if ( $scope.section === "happy" ) { $scope.section = "sad"; } else { $scope.section = "happy"; } }; } );
标签:
原文地址:http://www.cnblogs.com/leejersey/p/4775154.html