這是我做了什麼如何顯示過濾器函數中的數據/數組以查看內部表達式?
<div ng-app="myApp" ng-controller="PeopleCtrl">
<table border="1" ng-init="ageToShow=(people| underTwenty: 20).length >= 1">
而且我underTwenty功能是爲下
myApp.filter('underTwenty', function() {
return function(values, limit) {
var returnValue = [];
angular.forEach(values, function(val, ind) {
if (val.age < limit)
returnValue.push(val);
});
return returnValue;
};
我想顯示在我看來,的returnValue數組作爲表達這樣
<div ng-app="myApp" ng-controller="PeopleCtrl">
<table border="1" ng-init="ageToShow=(people| underTwenty: 20).length >= 1">
{{ageToShow}}
我知道這不是正確的方式,但它是什麼..請幫助...
Plunker:http://plnkr.co/edit/ceeF5tXFlBqInW5J3bdq?p=preview
你能解釋一下你想達到什麼嗎,用簡單的英語?鑑於人員名單,該頁面應該顯示什麼? – 2015-04-06 08:39:08
「我想在我的視圖中顯示returnValue數組,如下所示:」 在這種情況下,您不需要檢查ageToShow中的長度。你的問題不清楚。看到這個plunkr:http://plnkr.co/edit/LNhiN71UQu2bdCUIw8SR?p = preview – 2015-04-06 09:13:45