angularjs中ngSwitch的用法

來源:互聯網
上載者:User

標籤:

<!DOCTYPE html><html lang="zh-CN" ng-app="app" ng-controller="ctrl"><head>    <meta charset="utf-8">    <title>ng-switch的用法</title>    <link rel="stylesheet" href="../bootstrap.min.css"></head><body>    <h4>這個指令和ng-switch-when及on="propertyName"一起使用,可以在propertyName發生變化時渲染不同指令到視圖中</h4>    propertyName:<input type="text" ng-model="person.name">    <div ng-switch="person.name"> <!--這裡也可以這樣寫 ng-switch on="person.name" -->        <p ng-switch-default>這裡是預設顯示的值,嘗試輸入test1,test2,test3</p>        <span ng-switch-when="test1">{{person.name}}</span>        <span ng-switch-when="test2">{{person.name}}</span>        <span ng-switch-when="test3">{{person.name}}</span>    </div>    <script src="../angular.min.js"></script>    <script>        angular.module(‘app‘, [])        .controller(‘ctrl‘, [‘$scope‘, function($scope) {                    }])    </script></body></html>

 

這裡有個問題使我很疑惑

在使用中,大家可以看我上面給出的執行個體。這裡可以使用 ng-switch="" 也可以使用ng-switch on=""我一直無法明白這兩者的區別在哪裡,是否是版本的區別?如果是的話,那按照angular的風格應該將舊版的用法移除啊?還是說這兩者在使用上有區別?

 

angularjs中ngSwitch的用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.