0

coming from this working example: http://jsfiddle.net/h22f7596/ , I am trying to display the content of a json-file from my own OData Service in AngularJS.

HTML:

    <div ng-repeat="Adressen in results">
       {{Adressen.Street}}

        <strong style="float:right">
            {{Adressen.PLZ}}
        </strong>
    </div>
</div>

JS:

var myModule = angular.module("MyModule",['ODataResources']);
myModule.controller("MyController",function($scope,$odataresource){
$scope.results = 

$odataresource("https://xsgeos0015309874trial.hanatrial.ondemand.com/s0015309874trial/xsgeo/geotabelle/geoDB/GeotabelleODataService.xsodata/Adressen",  [],
                {
                  odata:{

                    method: 'GET',
                    isArray: true,
                    transformResponse: function (data) {
                    return angular.fromJson(data).value;
                    }
                  } 

                })
                .odata()


                .format("json")
                .filter("Street", "Kölner Straße")
                .filter("Hausnummer", "22")
                .take(5)
                .query();


                });

I dont know why no data is displayed, because in Chromes console, I can see that the OData request is transferred succesfully, but it is not displayed in my controller and when I look at console.log($scope.results) it shows me an empty array.

Please take a look at my example and tell me what I did wrong: http://jsfiddle.net/h22f7596/123/

Thank you in advance.

/edit: Updated Fiddle.

1 Answer 1

1

You were accessing the data wrong. If you would have printed the entire object you would have seen:

Object: {
    d: {
        results: {
            ....    
        }
    }
}

Change your return to:

return angular.fromJson(data).d.results

Fiddle: http://jsfiddle.net/h22f7596/124/

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

1 Comment

Is there a way to set the filters in the $odataresource dynamically?

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.