Angular2 Rxjs 404错误 [英] Angular2 Rxjs 404 error

查看:69
本文介绍了Angular2 Rxjs 404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试启动Angular2应用程序时出现以下错误:

I have the following error when trying to start my Angular2 application:

Failed to load resource: the server responded with a status of 404 (Not Found)
angular2-polyfills.js:332 Error: Error: XHR error (404 Not Found) loading http://localhost:55707/rxjs(…)

这是我的index.html:

Here is my index.html:

<!DOCTYPE html>
<html>
<head>
    <base href="/">
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Streak Maker</title>
    <link rel="icon" type="image/png" href="/images/favicon.png" />
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <!-- IE required polyfills, in this exact order -->
    <script src="node_modules/es6-shim/es6-shim.min.js"></script>
    <script src="node_modules/systemjs/dist/system-polyfills.js"></script>
    <script src="node_modules/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
    <script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
    <script src="node_modules/systemjs/dist/system.src.js"></script>
    <script src="node_modules/rxjs/bundles/Rx.js"></script>
    <script src="node_modules/angular2/bundles/angular2.dev.js"></script>
    <script src="node_modules/angular2/bundles/router.js"></script>
    <script src="node_modules/angular2/bundles/http.dev.js"></script>
    <script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <script>
      System.config({
        packages: {
          app: {
            format: 'register',
            defaultExtension: 'js'
          },
        },
      });
      System.import('app/boot')
            .then(null, console.error.bind(console));
    </script>
</head>
<body>
    <app>Loading...</app>
</body>
</html>

boot.ts:

///<reference path="../node_modules/angular2/typings/browser.d.ts"/> 

import {App} from './app.component';
import {bootstrap}  from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router';
import {HTTP_PROVIDERS} from 'angular2/http';
import {APP_PROVIDERS} from './app.module';

bootstrap(App, [
    //ROUTER_PROVIDERS,
    //HTTP_PROVIDERS,
    APP_PROVIDERS]);

我尝试将rxjs的路径放置在system.config中(它不起作用),但是由于我使用的是rxjs捆绑包,因此我不必这样做.

I've tried putting paths for rxjs in the system.config (it doesn't work) but since I'm using the rxjs bundle I shouldn't have to do that.

推荐答案

问题出在您的streak-maker/src/StreakMaker.Web/App/message-board/message-board.service.ts文件中

您应该导入rxjs模块,因为它在Rxjs库中不存在:

You should import the rxjs module since it doesn't exist in the Rxjs library:

import {Http} from 'angular2/http';
import {Injectable} from 'angular2/core';
import "rxjs"; // <-----

@Injectable()
export class MessageBoardService {
  constructor(private _http: Http) { }

  get() {
    return this._http.get('/api/messageboard').map(res => {
        return res.json();
    });
  }
}

您应该改用以下(rxjs/Rx):

import {Http} from 'angular2/http';
import {Injectable} from 'angular2/core';
import "rxjs/Rx"; // <-----

@Injectable()
export class MessageBoardService {
  (...)
}

您是对的:包含Rx.js文件足以提供Rxjs模块. SystemJS.config内不需要其他(显式)配置.

You're right: include the Rx.js file is enough to provide the Rxjs modules. No additional (explicit) configuration is required within SystemJS.config.

这篇关于Angular2 Rxjs 404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆