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?

share|improve this question

Is "devices.Devices" function?

I think code should be like

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

return devices.Devices;

});

share|improve this answer
    
{"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. – Coding Away yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.