我是AngularJS的新手。我试图使该功能可以用作过滤器:
index.html
<ul class="phones">
<li ng-repeat="phone in phones | filter:isLong">
{{phone.name}}
</li>
</ul>
controllers.js
phonecatApp.controller('PhoneListCtrl', function ($scope) {
$scope.phones = [
{'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'},
{'name': 'Motorola XOOM™ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'},
{'name': 'MOTOROLA XOOM™',
'snippet': 'The Next, Next Generation tablet.'}
];
$scope.islong = function(phone) {
var n = phone.name.length;
if ( n > 7) { return true } else { return false };
}
});
杰斯宾
但这不起作用...请帮助我。谢谢你的好意。
您只需要引用该函数,而无需调用它:
<li ng-repeat="phone in phones | filter:isLong">
该函数本身将单个项目作为参数:
$scope.isLong = function(phone) {
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句