J'ai cette directiveComment faire un ordre personnalisé par la logique en angulaire?
app.directive('myEnter', ['searchSvc', function (searchSvc) {
return{
restrict: 'A',
link: function (scope, element, attrs) {
element.bind("keyup", function() {
searchSvc.getPlanets(this.value)
.then(function(response){
scope.planets = response.data.results;
var filtered = [];
angular.forEach(scope.planets, function(item) {
filtered.push(item);
});
scope.filtered = filtered;
console.log(filtered);
scope.min = '10px';
}).catch(function(error){
$scope.error = response.data;
});
});
}
}
}]);
Dans les scope.planets j'ai:
scope.planets = {
"name":"Alderaan",
"population":"2000000000"
},
{
"name":"Yavin IV",
"population":"1000"
}
Je veux trier ce champ dans l'ordre croissant de la population, en quelque sorte mon orderby: 'population'
ne fonctionne pas. Quelqu'un pourrait-il m'aider avec la fonction personnalisée?
Dans le fichier html je,
<tr ng-repeat="planet in filtered">
<td><span>{{planet.name }}</span></td>
<td><span>{{planet.population}}</span></td>
</tr>
La population est une chaîne. Vous devez le convertir en nombre. – Hoyen