未找到Angular 2状态404

时间:2016-08-23 09:00:41

标签: javascript angularjs angular npm

我在我的应用上遇到2个错误:

无法加载资源:服务器响应状态为404(未找到) http://localhost:3002/angular2-infinite-scroll

angular2-polyfills.js:1243错误:XHR错误(404 Not Found)loading http://localhost:3002/angular2-infinite-scroll(...)

以下是相关网页:

import {Component} from 'angular2/core';
import {Router, CanDeactivate} from 'angular2/router';
import { InfiniteScroll } from 'angular2-infinite-scroll';

@Component({
selector: 'dapps',
directives: [ InfiniteScroll ],
templateUrl: '/app/dapps/templates/dapps.component.html',

在我所拥有的组件中进一步向下:

onScroll () {
    console.log('scrolled!!')
}

我使用以下方法安装了无限滚动npm包:

 npm install angular2-infinite-scroll --save

在我拥有的组件的模板文件中:

<div class="row" infinite-scroll
        [infiniteScrollDistance]="2"
        [infiniteScrollThrottle]="500"
        (scrolled)="onScroll()">
</div>

编辑尝试:

root上的

config.js:

System.config({
//use typescript for compilation
transpiler: 'typescript',
//typescript compiler options
typescriptOptions: {
emitDecoratorMetadata: true
},
//map tells the System loader where to look for things
map: {
'angular2-infinite-scroll': '~/angular2-infinite-scroll'
},
//packages defines our app package
packages: {
'angular2-infinite-scroll': {
main: 'angular2-infinite-scroll.js',
defaultExtension: 'js'
}
}

});

1 个答案:

答案 0 :(得分:3)

您必须在systemjs config中配置angular2-infinite-scroll。请参阅示例plunk中的config.js文件:

https://plnkr.co/edit/DzKAiAxtAleIrT0tsqtj?p=preview

 map: {

   'angular2-infinite-scroll': 'node_modules/angular2-infinite-scroll'
}

并且对于packages对象添加:

'angular2-infinite-scroll': {
  main: 'angular2-infinite-scroll.js',
  defaultExtension: 'js'
}