角1.6.5 angular.bootstrap注入错误

时间:2017-07-31 02:52:23

标签: javascript angularjs angular-ui-router meanjs

我有一个meanjs.org骨架应用程序,我已经转换为hapi-js而不是express,也转换为postgres而不是mongo,并使用OAUTH进行身份验证。 (好吧,真的,我只是喜欢服务器/客户端模块的文件夹结构 - 大声笑)

所有这些都有效,除了我的Angular部署(有点大不了)。角度为1.6.5(我没有时间学习TS和A2)。它加载所有模块组件而没有错误,路由等都没有错误。失败的一件事就是在document.ready:

之后的这一行

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

如果我对此进行评论并将ng-app="appName"添加到HTML而不是使用bootstrap方法,我会得到相同的结果......此错误:

  

由于以下原因无法实例化模块appN:错误:[$ injector:modulerr]

我已经确认其他所有内容都在加载而且没有错误...不确定从哪里开始...有什么建议吗?

@matias请求完整代码,这里是angular config:

(function (window) {
  'use strict';

  var applicationModuleName = 'appName';

  var service = {
    applicationEnvironment: window.env,
    applicationModuleName: applicationModuleName,
    applicationModuleVendorDependencies: ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap','ui-notification'],
    registerModule: registerModule
  };

  window.ApplicationConfiguration = service;

  // Add a new vertical module
  function registerModule(moduleName, dependencies) {
    // Create angular module
    angular.module(moduleName, dependencies || []);

    // Add the module to the AngularJS configuration file
    angular.module(applicationModuleName).requires.push(moduleName);
  }

  // Angular-ui-notification configuration
  angular.module('ui-notification').config(function(NotificationProvider) {
    NotificationProvider.setOptions({
      delay: 2000,
      startTop: 20,
      startRight: 10,
      verticalSpacing: 20,
      horizontalSpacing: 20,
      positionX: 'right',
      positionY: 'bottom'
    });
  });
}(window));

这里是角度init(首先是config加载,然后是init):

(function (app) {
  'use strict';

  // Start by defining the main module and adding the module dependencies
  angular
    .module(app.applicationModuleName, app.applicationModuleVendorDependencies);

  // Setting HTML5 Location Mode
  angular
    .module(app.applicationModuleName)
    .config(bootstrapConfig);

  bootstrapConfig.$inject = ['$compileProvider', '$locationProvider', '$httpProvider', '$logProvider'];

  function bootstrapConfig($compileProvider, $locationProvider, $httpProvider, $logProvider) {
    $locationProvider.html5Mode({
      enabled: true,
      requireBase: false
    }).hashPrefix('!');

    $httpProvider.interceptors.push('authInterceptor');

    // Disable debug data for production environment
    // @link https://docs.angularjs.org/guide/production
    $compileProvider.debugInfoEnabled(app.applicationEnvironment !== 'production');
    $logProvider.debugEnabled(app.applicationEnvironment !== 'production');
  }


  // Then define the init function for starting up the application
  angular.element(document).ready(init);

  function init() {
    // Fixing facebook bug with redirect
    if (window.location.hash && window.location.hash === '#_=_') {
      if (window.history && history.pushState) {
        window.history.pushState('', document.title, window.location.pathname);
      } else {
        // Prevent scrolling by storing the page's current scroll offset
        var scroll = {
          top: document.body.scrollTop,
          left: document.body.scrollLeft
        };
        window.location.hash = '';
        // Restore the scroll offset, should be flicker free
        document.body.scrollTop = scroll.top;
        document.body.scrollLeft = scroll.left;
      }
    }

    // Then init the app
    angular.bootstrap(document, [app.applicationModuleName]);
  }
}(ApplicationConfiguration));

2 个答案:

答案 0 :(得分:1)

试试这个,首先你必须创建你的应用程序(名称+依赖项列表):

var app = angular.module('myApp', []);

然后,引导您的应用:

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

答案 1 :(得分:0)

好。我感到羞怯。我尝试了一种更简单的方法,并介入我正在做的事情,看看能不能找到罪魁祸首。

事实证明,我注入ui.bootstrap是项目失败(感谢@estus - 你的评论让我深入挖掘其他模块)。它失败了,因为我很蹩脚,胖子在资产管道中找到了路径,所以图书馆并没有存在于页面上。

*羞愧* *

谢谢大家的快速帮助。非常感谢。