如何在ES6中导入名称中带有连字符的angularjs模块

时间:2018-11-28 14:42:03

标签: angularjs webpack ecmascript-6 import

我正在尝试将我的angularjs应用程序中的md-steppers npm软件包与webpack一起使用,并且遇到了麻烦。 angular-cache-buster npm包

也会发生这种情况

因此,我通过npm安装了它,并使用了以下导入语句

import mdSteppers from 'md-steppers';

并按如下所示将其添加到angularjs DI

angular.module('myapp', [ mdSteppers ]

我收到下面显示的错误

Uncaught Error: [$injector:modulerr] Failed to instantiate module bolt due to:
Error: [$injector:modulerr] Failed to instantiate module {} due to:
Error: [ng:areq] Argument 'module' is not a function, got Object
http://errors.angularjs.org/1.5.5/ng/areq?p0=module&p1=not%20a%20function%2C%20got%20Object
    at eval (webpack:///./node_modules/angular/angular.js?:68:12)
    at assertArg (webpack:///./node_modules/angular/angular.js?:1880:11)
    at assertArgFn (webpack:///./node_modules/angular/angular.js?:1890:3)
    at eval (webpack:///./node_modules/angular/angular.js?:4573:11)
    at forEach (webpack:///./node_modules/angular/angular.js?:322:20)
    at loadModules (webpack:///./node_modules/angular/angular.js?:4548:5)....

我检查了此npm软件包的模块名称,如下所示

angular.module('md-steppers', [
  'material.core',
  'material.components.icon']);

/**
 * @ngdoc directive
 * @name mdStep
 * @module md-steppers
 *
 * @restrict E

任何帮助将不胜感激。谢谢

2 个答案:

答案 0 :(得分:0)

尝试以下操作:

import {name as mdStepper} from 'md-steppers';
angular.module('myapp', [mdSteppers]);

答案 1 :(得分:0)

此软件包中没有任何导出的模块。
因此,您只能通过以下方式使用它:

import angular from 'angular';    
import mdStepper from 'md-steppers';

angular.module('myapp', ['md-steppers']);