AngularJs 控制器和过滤器的用法

控制器和过滤器的用法

<html>
<script src= "http://apps.bdimg.com/libs/angular.js/1.3.9/angular.min.js"></script>
<body>

<p>ng-controller 指令定义了应用程序控制器。这个控制器是自己定义的</p>
<div ng-app="myApp" ng-controller="namesCtrl">

<p>输入过滤:</p>

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

<p>这里用到了过滤器,‘|’为管道过滤器,后面可以接:<br/>
currency    格式化数字为货币格式。<br/>
filter    从数组项中选择一个子集。<br/>
lowercase    格式化字符串为小写。<br/>
orderBy    根据某个表达式排列数组。<br/>
uppercase    格式化字符串为大写。</p>
<ul>
  <li ng-repeat="x in names | filter:test | orderBy:'country'">
    {{ fullName(x) + ', ' + x.country | uppercase }}
  </li>
</ul>

</div>

<script>
angular.module('myApp', []).controller('namesCtrl', 
function($scope) {
    $scope.names 
= [
        {firstName:'Jani',lastName:'a',country:'Norway'},
        {firstName:'Hege',lastName:'b',country:'Sweden'},
        {firstName:'Kai',lastName:'c',country:'Denmark'}
    ];
    $scope.fullName 
= function($x) {
        
return $x.firstName + " " + $x.lastName;
    }
});    
</script>

</body>
</html>


眼镜蛇

posted on 2015-09-08 11:43 眼镜蛇 阅读(168) 评论(0)  编辑  收藏 所属分类: AngularJS


只有注册用户登录后才能发表评论。


网站导航:
 
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿(6)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜