Question

I can't figure out why the code below is not filtering just the values with unique_id of "027". I've tried it as a string as well '027'...

JSON file:

[
  {
    "unique_id":"027",
    "title":"How Speed Relates to Energy",
    "state":"NY",
    "state_id":"1.S2.3a"
  }
]

Here my 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();
    });

})

Here's my 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>
Was it helpful?

Solution

you need to correct your html markup like this, as in your JSON unique_id is a string:

<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>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top