控制器和过滤器的用法
<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>
眼镜蛇