AngularJs的過濾器

所謂過濾器就是過濾得到自己想要的數據

currency 格式化數字爲貨幣格式。
filter 從數組項中選擇一個子集。
lowercase 格式化字符串爲小寫。
orderBy 根據某個表達式排列數組。
uppercase 格式化字符串爲大寫。
uppercase 過濾器將字符串格式化爲大寫:

<div ng-app="myApp" ng-controller="personCtrl">

<p>姓名爲 {{ lastName | uppercase }}</p>

</div>

orderBy 過濾器根據表達式排列數組:

<div ng-app="myApp" ng-controller="namesCtrl">

<ul>
  <li ng-repeat="x in names | orderBy:'country'">
    {{ x.name + ', ' + x.country }}
  </li>
</ul>

</div>

filter 過濾器從數組中選擇一個子集: 這個是可以用多個過濾器的 這過濾器是隻顯示和輸入內容相關的數據

<div ng-app="myApp" ng-controller="namesCtrl">

<p><input type="text" ng-model="test"></p>

<ul>
  <li ng-repeat="x in names | filter:test | orderBy:'country'">
    {{ (x.name | uppercase) + ', ' + x.country }}
  </li>
</ul>

</div>




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章