gpt4 book ai didi

Angular2 Rxjs 404 错误

转载 作者:太空狗 更新时间:2023-10-29 17:30:10 27 4
gpt4 key购买 nike

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

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:

<!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 包,所以我不应该这样做。

最佳答案

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

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

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 中不需要额外的(明确的)配置。

关于Angular2 Rxjs 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36239813/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com