AngularJS NG-ripetizione filtro sul valore statico non funziona
-
20-12-2019 - |
Domanda
Non riesco a capire perché il codice qui sotto non filtra solo i valori con Unique_ID di "027".L'ho provato come una stringa pure "027 '...
File JSON:
[
{
"unique_id":"027",
"title":"How Speed Relates to Energy",
"state":"NY",
"state_id":"1.S2.3a"
}
]
.
Qui il mio controller:
var abApp = angular.module('abApp', []);
abApp.factory('abData', function($http, $q) {
var deffered = $q.defer();
var data = [];
var abData = {};
abData.async = function() {
$http.get('/data/ab_activities.json')
.success(function(ab) {
data = ab;
deffered.resolve();
});
return deffered.promise;
};
abData.data = function() {
return data;
};
return abData;
});
abApp.controller("abEE", function(abData, $scope) {
var abApp = this;
abData.async().then(function(ab) {
abApp.alignments = abData.data();
});
})
.
Ecco il mio html:
<div ng-controller="abEE as ee">
<ul>
<li ng-repeat="align in ee.alignments | filter:{unique_id : 027} ">
{{align.unique_id}} - {{align.state}}, {{align.state_id}}
</li>
</ul>
</div>
. Soluzione
È necessario correggere il tuo markup HTML come questo, come nel tuo JSON UNICHE_ID è una stringa:
<div ng-controller="abEE as ee">
<ul>
<li ng-repeat="align in ee.alignments | filter:{unique_id : '027'} ">
{{align.unique_id}} - {{align.state}}, {{align.state_id}}
</li>
</ul>
.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow