0

I can fake getting data from json file with using $http but with $resource/ $httpBackend I don't get any results

$http.get (works)

 $http.get('api/devices.json')
      .then(function (result) {

      ...//

Above works just fine but the $httpBackend will work with json inline , but not pointing at JSON file

Controller file which calls the deviceResourceMock module

deviceResource.query(function(data) {    
       vm.devices = data; 
    });

deviceResourceMock module

app.run(function ($httpBackend) {

    var devices = 'test.json';  // Put new json file in same directory

    // ABOVE DOES NOT WORK 

This DOES work below though

var devices = {"Devices":  [
        {
            "DeviceId": 1,
            "DeviceStatus": "Leaf Rake",
            "id": "GDN-0011",
            "ha": "Leaf rake with 48-inch wooden handle.",
            "Urt": "blah"
        }
]};

URL and WhenGet

var deviceUrl = "/api/devices";
$httpBackend.whenGET(deviceUrl).respond(devices.Devices);

Thoughts on why it doesn't work?

1 Answer 1

0

Is "devices.Devices" function?

I think code should be like

$httpBackend.whenGET(deviceUrl).respond(function(method,url,data) {

return devices.Devices;

});

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

1 Comment

{"Devices": is how the data will be wrapped in that object ... its how the Web api is sending data, thus it is needed to do devices.Devices with that code i showed, it is valid JSON to wrap it It is not a function.

Your Answer

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