将Angular2-wizard包添加到项目中

时间:2017-06-10 20:49:25

标签: angular npm

我从Angular Quickstart seed开始一个Angular项目。 我一直在创建自己的组件,现在我想添加Angular2-wizard npm包

我使用以下命令

安装了软件包
$ npm install angular2-wizard --save

在其安装部分中说明,然后尝试按照所有建议的步骤使用该组件。我可以在项目的node_modules文件夹下看到以插件命名的文件夹。

当我使用npm start运行项目时,我发现此错误

  

错误:(SystemJS)XHR错误(404 Not Found)loading http://localhost:3000/angular2-wizard

该项目有一个工作演示(angular2-wizard-demo),但似乎没有使用SystemJS。我也尝试了this answer添加行

的建议
'angular2-wizard':           'npm:angular2-wizard/dist/index.js'

在地图配置下,但现在我在程序包加载其组件时会收到404错误

  

http://localhost:3000/node_modules/angular2-wizard/dist/src/wizard.component加载http://localhost:3000/node_modules/angular2-wizard/dist/index.js为“./src/wizard.component”时出错   堆栈跟踪:   (SystemJS)XHR错误(404 Not Found)loading http://localhost:3000/node_modules/angular2-wizard/dist/src/wizard.component

这是app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule }   from '@angular/forms';

import { AppComponent }  from './app.component';

import { FormWizardModule } from 'angular2-wizard';

import { PizzaService } from './services/pizza.service'

@NgModule({
  imports:      [
                  BrowserModule,
                  FormsModule,
                  FormWizardModule
                ],
  declarations: [ AppComponent ],
  providers:    [ PizzaService ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

有关如何将此包添加到我的项目的任何提示?

1 个答案:

答案 0 :(得分:2)

404是因为它试图访问 node_modules/angular2-wizard/dist/src/wizard.component不存在。

这是因为angular2-wizard内部编译的index.js正在尝试执行require('./src/wizard.component')。我相信他们的分发不是失败证明,但SystemJS为您提供以下内容: -

..在system.config.js内寻找

// packages tells the System loader how to load when no filename and/or no

将以下内容添加到' packages`中的systemjs.config.js:

  'node_modules/angular2-wizard/dist/src/': {
    defaultExtension: 'js'
  }

现在你的systemjs.config.js应该如下所示:

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      'app': 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',

      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'angular2-wizard':           'npm:angular2-wizard/dist/index.js'
    },

    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        defaultExtension: 'js',
        meta: {
          './*.js': {
            loader: 'systemjs-angular-loader.js'
          }
        }
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'node_modules/angular2-wizard/dist/src/': {
        defaultExtension: 'js'
      }
    }
  });
})(this);