AngularJS控制器和過濾器學習(三),angularjs控制器

來源:互聯網
上載者:User

AngularJS控制器和過濾器學習(三),angularjs控制器

AngularJS控制器

AngularJS 控制器 控制 AngularJS 應用程式的資料。
AngularJS 控制器是常規的JavaScript對象

<h2>AngularJS 控制器屬性</h2><div ng-app="" ng-controller="MyController">   <p>姓名:<input type="text" ng-model="person.name"></p>    <p>性別: <input type="text" ng-model="person.sex"></p>    <div>資訊: {{person.info()}}  </div></div><script type="text/javascript">    function MyController($scope){        $scope.person = {            name:"LanFeng",            sex:"女",            info:function(){                var x;                x = $scope.person;                return x.name + " "+ x.sex;            }        }    }</script><h2>AngularJS 控制器方法</h2><div ng-app="" ng-controller="MyController">    <p>姓名:<input type="text" ng-model="person.name"></p>    <p>性別: <input type="text" ng-model="person.sex"></p>    <div>資訊: {{info()}}  </div></div><script type="text/javascript">    function MyController($scope){        $scope.person = {            name:"LanFeng",            sex:"女"        };        $scope.info=function(){            var x;            x = $scope.person;            return x.name + " "+ x.sex;        }    }</script>

AngularJS過濾器

currency 格式化數字為貨幣格式。
filter 從數組項中選擇一個子集。
lowercase 格式化字串為小寫。
orderBy 根據某個運算式排列數組。
uppercase 格式化字串為大寫。

過濾器可以通過一個管道字元(|)和一個過濾器添加到運算式中。

<h2>AngularJS 控制器方法</h2><div ng-app="" ng-controller="MyController">    <p>姓名:<input type="text" ng-model="person.name"></p>    <p>性別: <input type="text" ng-model="person.sex"></p>    <div>資訊: {{person.name | }}  </div></div><script type="text/javascript">    function MyController($scope){        $scope.person = {            name:"LanFeng",            sex:"女"        }    }</script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.