由于$ injector:strictdi,无法实例化模块ng

时间:2016-07-25 20:40:40

标签: angularjs angular-bootstrap

我已将“Angular”项目“迁移”到ES6,只需将babelify添加到我的gulp browserify任务中即可。一切都很好,虽然我从周末回来,有些事情破了......

我的应用现在抱怨以下内容:

angular.min.js:formatted:7382 Error: [$injector:modulerr] http://errors.angularjs.org/1.5.5/$injector/modulerr?p0=ng&p1=Error%3A%20%5…0%20%20at%20bb%20(http%3A%2F%2Flocalhost%3A3000%2Fjs%2Flibs.js%3A173%3A246)
    at Error (native)
    at http://localhost:3000/js/libs.js:136:412
    at http://localhost:3000/js/libs.js:170:134
    at q (http://localhost:3000/js/libs.js:137:355)
    at g (http://localhost:3000/js/libs.js:169:222)
    at bb (http://localhost:3000/js/libs.js:173:246)
    at c (http://localhost:3000/js/libs.js:151:19)
    at Object.yc [as bootstrap] (http://localhost:3000/js/libs.js:151:332)
    at http://localhost:3000/js/app.js:745:11
    at http://localhost:3000/js/libs.js:260:226

打开错误链接时:

Failed to instantiate module ng due to:
Error: [$injector:strictdi] http://errors.angularjs.org/1.5.5/$injector/strictdi?p0=f...)
    at Error (native)
    at http://localhost:3000/js/libs.js:136:412
    at Function.bb.$$annotate (http://localhost:3000/js/libs.js:328:487)
    at e (http://localhost:3000/js/libs.js:170:442)
    at Object.invoke (http://localhost:3000/js/libs.js:171:163)
    at d (http://localhost:3000/js/libs.js:169:321)
    at http://localhost:3000/js/libs.js:169:445
    at q (http://localhost:3000/js/libs.js:137:355)
    at g (http://localhost:3000/js/libs.js:169:222)
    at bb (http://localhost:3000/js/libs.js:173:246

进一步打开错误时:

function($provide is not using explicit annotation and cannot be invoked in strict mode

我不明白这一点是最后一部分function($provider ......这不在我的代码中,而且......它在今天重新运行gulp任务之前有效。

以下是我引导应用的方式:

import appConstant from './app.constant';
import appConfig from './app.config';
import appRun from './app.run';
import AppComponent from './app.component';
import coreModule from './core/core';
import viewsModule from './views/views';
import permissionsModule from './permissions/permissions';
import formModules from './forms-directives/form-blocks';
import DAOModules from './DAO/dao';
import './templates';

const requires = [
  'ngCookies',
  'ngLocale',
  'ngAnimate',
  'ngMessages',
  'ngRoute',
  'ngSanitize',
  'permission',
  'permission.ng',
  'mgcrea.ngStrap',
  'ui.tinymce',
  'ui.mask',
  'pascalprecht.translate',
  'templates',
  coreModule.name,
  viewsModule.name,
  permissionsModule.name,
  formModules.name,
  DAOModules.name,
];

// require('./templates');
// requires.push('templates');

function extractRoles(userData) {
  const regex = /^ind/i;

  return _(userData)
    .map((value, prop) => {
      const role = regex.test(prop) && value === true
        ? prop.replace(/([A-Z])/g, '_$1').toUpperCase().substr(4)
        : null;

      return role;
    })
    .compact() // remove falsy from array
    .value();
}

function getRoles() {
  const initInjector = angular.injector(['ng']);
  const $http = initInjector.get('$http');

  return $http.get('some-real-here') // I removed the real url for privacy reasons
    .then((response) => response)
    .catch((e) => console.log('error loading userData', e));
}

// create and bootstrap application
getRoles()
  .then((roles) => {
    angular.module('app', requires)
      .config(appConfig)
      .run(appRun)
      .constant('APP_SETTINGS', appConstant({
        protocol: 'https',
        host: 'some-real-here', // I removed the real url for privacy reasons
        port: 3000, 
        mock: false,
      }))
      .constant('STATUT_MAP', {
        NOUV: '/completeoffre',
        COMP: '/analyseroffre',
        ACCP: '/documenter',
        DOCU: '/statueroffre',
        APPR: '/enregistreroffre',
        ENRE: '/evalueroffre',
      })
      .value('userObj', {
        user: roles.data,
        roles: extractRoles(roles.data),
      })
      .component('app', AppComponent);

    angular.bootstrap(document, ['app'], {
      strictDi: true,
    });
  });

angular.bootstrap(...)执行时会触发错误。

1 个答案:

答案 0 :(得分:-4)

删除strictDi:true,就像这样

angular.bootstrap(document, ['app']);