找不到文件ng2-page-scroll

时间:2017-03-24 03:40:32

标签: angular

我尝试使用库ng2-page-scroll但是按照他们的步骤显示文件未找到ng2-page-scroll。      它似乎是systemjs.config中的错误,任何人都知道如何解决这个问题?

安装ng2-page-scroll

npm install ng2-page-scroll --save

在app.module

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

import { AppComponent }  from './app.component';
import {Ng2SimplePageScrollModule} from "ng2-simple-page-scroll";

@NgModule({
  imports:      [ BrowserModule ,Ng2SimplePageScrollModule.forRoot()],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

在systemjs.config

(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',
      'ng2-simple-page-scroll/ng2-simple-page-scroll': 'ng2-simple-page-scroll/bundles/ng2-simple-page-scroll.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'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app : {defaultExtension: 'js', main: './main.js'},
      rxjs: {defaultExtension: 'js'},
    }
  });
})(this);

这是找不到的结果文件 ng2-page-scroll Not Found

1 个答案:

答案 0 :(得分:0)

替换

'ng2-simple-page-scroll/ng2-simple-page-scroll': 'ng2-simple-page-scroll/bundles/ng2-simple-page-scroll.umd.js',

'ng2-simple-page-scroll': 'npm:ng2-simple-page-scroll/bundles/ng2-simple-page-scroll.umd.js',

为什么需要这样做?

首先你写的是

import {Ng2SimplePageScrollModule} from "ng2-simple-page-scroll";

因此模块说明符"ng2-simple-page-scroll"必须与map

中的packagesystemjs.config.js条目相对应

其次,systemjs.config.js

的路径输入
paths: {
  // paths serve as alias
  'npm:': 'node_modules/'
},

表示前缀npm:指向node_modules目录。 map中具有该前缀的所有其他包进一步证明了这一点。