【问题标题】:Add Angular Module添加角度模块
【发布时间】:2015-04-20 14:38:28
【问题描述】:

我正在尝试将 angular-gantt 插件添加到我的应用程序中。首先;

angular.module('myApp',['directives', 'services', 'controllers', ... and some more]

然后,当我的应用程序需要 angular-gantt 时,我想向“myApp”添加一些额外的模块,例如;

angular.module('myApp',['gantt','gantt-sortable','gantt-movable',.. and some more]

但是当我这样做时,页面消失了,没有任何效果。我该如何解决这个问题。

【问题讨论】:

  • 检查控制台是否有错误。您是否在 HTML 页面中包含库文件?
  • 向我们展示控制台日志和代码本身
  • 这两行代码是否都在您的代码中运行?还是只有一个?
  • 项目太大,无法分享。当我尝试添加新模块时,现有模块会丢失。这就是问题。我想在不丢失现有模块的情况下向“myApp”添加新模块。

标签: angularjs angularjs-module


【解决方案1】:

添加到现有模块时需要使用不同的语法,否则模块会被重新创建/覆盖。 来自https://docs.angularjs.org/guide/module

请注意,使用 angular.module('myModule', []) 将创建 模块 myModule 并覆盖任何名为 myModule 的现有模块。采用 angular.module('myModule') 检索现有模块。

以及下面的例子:

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

// add some directives and services
myModule.service('myService', ...);
myModule.directive('myDirective', ...);

// overwrites both myService and myDirective by creating a new module
var myModule = angular.module('myModule', []);

// throws an error because myOtherModule has yet to be defined
var myModule = angular.module('myOtherModule');

编辑:也请在这里查看更详细的讨论: re-open and add dependencies to an already bootstrapped application

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 2018-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多