码迷,mamicode.com
首页 > Web开发 > 详细

angularjs ng-switch

时间:2015-09-01 12:29:59      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

    <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";

                    }

                };

            }
        );

 

angularjs ng-switch

标签:

原文地址:http://www.cnblogs.com/leejersey/p/4775154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!