在角度流星中添加模块

问题描述 投票:0回答:1

我正在使用角度流星(Angular1)开发一个Web应用程序。这使用webpack作为模块捆绑器。自从我开始以来,我发现无法将npm / bower模块注入我的app模块。

我经常遇到如下错误:

Error: [$injector:nomod] Module xxx 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.

我通常遵循官方文档,其中包括:

  • 下载npm模块
  • 在我的index.html中包含脚本
  • 将模块添加到我的app模块

但这总是给出上面的错误。

然后我尝试不同的技术,例如使用以下命令导入页面顶部的模块:

import exampleModule from 'angular-example-module';

并将exampleModule添加到我的模块列表中,但似乎没有任何工作。

我以前使用过没有webpack的角度,从来没有遇到过这个问题。我错过了什么吗?有一个我不知道的特定程序吗?

angularjs webpack module angular-meteor
1个回答
0
投票

找到答案,以防其他人有同样的问题。

您必须在主javascript文件中导入模块,如下所示:

import moduleVariable from '<path-to-module>';

然后在应用程序模块的依赖项中包含moduleVariable。

© www.soinside.com 2019 - 2024. All rights reserved.