0

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>

1 Answer 1

1

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>

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks V31, that was it... the template system I'm using was messing with the html output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.