Search code examples
angularjshttpbackend

Unable to Inject $httpBackend


I am using Angular 1.5 to write mocked services for my project by following this little example: https://embed.plnkr.co/qsmx8RUmQlXKkeXny7Rx/

This is a simple code that I have written so far:

function() {
 'use strict';

  angular.module('agMock', ['ag', 'ngMockE2E'])
   .run(function($httpBackend) {

     $httpBackend.whenGET('https://localhost:8080/api/users')
     .respond({user: 'fooBarBaz', roles: ['admin', 'user']});

   });
 })();

'ag' is the parent module of my project for which I am going to write mocks. When I try and run this, I get the error saying 'unknown provider: $httpBackend' although I have included angular.mocks library. Can anybody take a guess what can go wrong?


Solution

  • So I figured out why was I getting this error. The project in which I was getting this error uses gulp to inject dependencies and generate index.html files for dev and mocked environment. In the template index.html file, I had the main parent module, "äg" referenced in the ng-app. I skipped the part where I had to substitute "agMock" instead of "ag" in the ng-app while generating mocked index. So this was the problem. Phew.