最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Module 'ngMockE2E' is not available! AngularJS - Stack Overflow

programmeradmin0浏览0评论

Getting the following error in my browser:

Uncaught Error: [$injector:modulerr] Failed to instantiate module sayHiApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngMockE2E due to:
Error: [$injector:nomod] Module 'ngMockE2E' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
.2.15/$injector/nomod?p0=ngMockE2E
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:78:12
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:1611:17
    at ensure (http://127.0.0.1:9000/bower_ponents/angular/angular.js:1535:38)
    at module (http://127.0.0.1:9000/bower_ponents/angular/angular.js:1609:14)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3717:22
    at Array.forEach (native)
    at forEach (http://127.0.0.1:9000/bower_ponents/angular/angular.js:323:11)
    at loadModules (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3711:5)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3718:40
    at Array.forEach (native)
.2.15/$injector/modulerr?p0=ngMockE2E&p1=Error…ngular%2Fangular.js%3A3718%3A40%0A%20%20%20%20at%20Array.forEach%20(native)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:78:12
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3745:15
    at Array.forEach (native)
    at forEach (http://127.0.0.1:9000/bower_ponents/angular/angular.js:323:11)
    at loadModules (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3711:5)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3718:40
    at Array.forEach (native)
    at forEach (http://127.0.0.1:9000/bower_ponents/angular/angular.js:323:11)
    at loadModules (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3711:5)
    at createInjector (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3651:11)
.2.15/$injector/modulerr?p0=sayHiApp&p1=Error%…F%2F127.0.0.1%3A9000%2Fbower_ponents%2Fangular%2Fangular.js%3A3651%3A11) angular.js:78

My app.js looks like this:

'use strict';

angular
  .module('sayHiApp', [
    'ngCookies',
    'ngMockE2E',
    'ngResource',
    'ngSanitize',
    'ngRoute'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  })
  .run(function($httpBackend) {

    var name = '';

    $httpBackend.whenPOST('/name').respond(function(method, url, data) {
      name = angular.fromJson(data);
      return [200, name, {}];
    });

    $httpBackend.whenGET('/name').respond(name);

  });

Am I missing something?

Getting the following error in my browser:

Uncaught Error: [$injector:modulerr] Failed to instantiate module sayHiApp due to:
Error: [$injector:modulerr] Failed to instantiate module ngMockE2E due to:
Error: [$injector:nomod] Module 'ngMockE2E' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs/1.2.15/$injector/nomod?p0=ngMockE2E
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:78:12
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:1611:17
    at ensure (http://127.0.0.1:9000/bower_ponents/angular/angular.js:1535:38)
    at module (http://127.0.0.1:9000/bower_ponents/angular/angular.js:1609:14)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3717:22
    at Array.forEach (native)
    at forEach (http://127.0.0.1:9000/bower_ponents/angular/angular.js:323:11)
    at loadModules (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3711:5)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3718:40
    at Array.forEach (native)
http://errors.angularjs/1.2.15/$injector/modulerr?p0=ngMockE2E&p1=Error…ngular%2Fangular.js%3A3718%3A40%0A%20%20%20%20at%20Array.forEach%20(native)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:78:12
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3745:15
    at Array.forEach (native)
    at forEach (http://127.0.0.1:9000/bower_ponents/angular/angular.js:323:11)
    at loadModules (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3711:5)
    at http://127.0.0.1:9000/bower_ponents/angular/angular.js:3718:40
    at Array.forEach (native)
    at forEach (http://127.0.0.1:9000/bower_ponents/angular/angular.js:323:11)
    at loadModules (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3711:5)
    at createInjector (http://127.0.0.1:9000/bower_ponents/angular/angular.js:3651:11)
http://errors.angularjs/1.2.15/$injector/modulerr?p0=sayHiApp&p1=Error%…F%2F127.0.0.1%3A9000%2Fbower_ponents%2Fangular%2Fangular.js%3A3651%3A11) angular.js:78

My app.js looks like this:

'use strict';

angular
  .module('sayHiApp', [
    'ngCookies',
    'ngMockE2E',
    'ngResource',
    'ngSanitize',
    'ngRoute'
  ])
  .config(function ($routeProvider) {
    $routeProvider
      .when('/', {
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .otherwise({
        redirectTo: '/'
      });
  })
  .run(function($httpBackend) {

    var name = '';

    $httpBackend.whenPOST('/name').respond(function(method, url, data) {
      name = angular.fromJson(data);
      return [200, name, {}];
    });

    $httpBackend.whenGET('/name').respond(name);

  });

Am I missing something?

Share Improve this question asked Dec 6, 2014 at 7:48 user818700user818700 3
  • 11 Are you loading angular-mocks.js script file? – dfsq Commented Dec 6, 2014 at 7:59
  • Ho oh... I think that's the issue.. let me quickly bower install – user818700 Commented Dec 6, 2014 at 8:12
  • 1 Yep that was the error. Thanks! – user818700 Commented Dec 6, 2014 at 8:22
Add a ment  | 

2 Answers 2

Reset to default 2

The angular.mocks.js file consists of a number of modules helpful in mocking and testing. The most used ones are ngMock, ngMockE2E which provide the mocks for some of the most used ponents such as $timeout, $rootScope, $controller, $httpBackend ($httpBackend is part of ngMockE2E).

In order to use any of these modules as dependecy you need to load angular.mocks.js. Just add this script in your html file to remove the [$injector:modulerr] which is an error caused when the module added as dependency is not found or its file has not been loaded

I only add to use $httpBackend, so only 'ngMocksE2E' module was necessary, so I did:

import angular from 'angular';
// it exports moduleName that is 'ngMockE2E'
import ngMockE2EModuleName from 'angular-mocks/ngMocksE2E.js';

export default angular.module('app', [ngMockE2EModuleName]);
发布评论

评论列表(0)

  1. 暂无评论