1

i have an json array like this

//data.json
{
"one":   [ {"name":"john"},{"name":"joe"},{"name":"vicky"} ],
"two":   [ {"name":"mark"},{"name":"nike"},{"name":"albert"} ]
}

//filter.js
angular.module('eventFilters', ['calenderServices']).filter('compare', function(Name) {
var e=Name.query();

return function(input) {
alert(e['one'].length) //-->displays nothing
}

i am trying to retrieve the length of the array "one" and "two", but jsondata['one'].length is not returning the length, it is not displaying any thing. My angular restful services which i have used to get the json data from external file is correct, no doubt in that. since i am getting json data in filter, i couldn't use $scope.e=Name.query(); so i tried using 'var', it was working fine with my old json data, but not with my new json file. what may be the problem?

Thanks in advance

3
  • is there any way to use $scope in filter??? Commented Dec 15, 2012 at 12:57
  • Have you inspected the object you get, so the 'e'? If so how does it look like? Commented Dec 15, 2012 at 13:05
  • yes it displays nothing. just empty. Commented Dec 15, 2012 at 15:29

1 Answer 1

1

Not entirely sure what is the exact problem you are trying to solve here but the issue into which you are bumping here is that you've got an async call (.query()) that won't return results immediately (I suspect that you are using $resource and its syntax might suggest that is synchronous, more info here: https://stackoverflow.com/a/11966512/1418796).

Now, filters are not prepared to work with asynchronous results really so what you are trying to do here won't work. Ultimately the issue is more linked to the asynchronous function calls that to filters.

Would love to help more here but I'm not clear what you are trying to achieve, functionally speaking.

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

Comments

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.