My background is not in web development so my terminology might be off, apologies.
In short, I have trouble figuring out where $httpBackend
is serving data. This question is as much about finding a fix as it is about understanding better how $httpBackend
works in general. Here more details.
I am creating a single page app with AngularJS. As seeder I'm using the AngularJS "Phone Catalog" sample project from their website, which uses npm and bower.
I will need the app to access some RESTful web services, which for the time being I want to mock. I came across ngMockE2E, which I am now using. So instead of just loading the main app.js in my index.html, I am now loading devapp.js as well, which has my app and ngMockE2E as dependencies:
var devapp = angular.module('devapp', ['app', 'ngMockE2E']);
.
Within devapp
I mock my web service like so:
devapp.run(function($httpBackend) {
var items = [{{"id": 1, "price": 5}, {"id": 2, "price": 10}}];
$httpBackend.whenGET('/json/items').respond(items);
// let all other requests through to app
$httpBackend.whenGET(/^\w+.*/).passThrough();
});
Now when I run my app and I build services that send $http
calls to /json/items, it all works fine.
But I'd like to see the output in my actual browser. For some reason I can't seem to find the URL!
My index.html kicks in when I go to localhost:8000/app/
, and most addresses for my partials look like localhost:8000/app/#/login
and so on. But where do I have to go to get the JSON form my fake $httpBackend
?
I tried localhost:8000/json/items
which gives me "Not Available", and localhost:8000/app/#/json/items
or localhost:8000/app/json/items
, which just sends me to my index.html with no partials loaded, and I've tried every combination I could think of.