当前位置:  开发笔记 > 编程语言 > 正文

如何使用Angular 2(beta和更新版本)加载RxJS(和zone.js/reflect-metadata)?

如何解决《如何使用Angular2(beta和更新版本)加载RxJS(和zone.js/reflect-metadata)?》经验,为你挑选了1个好方法。

截至Angular 2 Alpha 54(更改日志),RxJS不再包含在Angular 2中.

更新:原来zone.js并且reflect-metadata也被排除在外.

因此,我现在遇到以下错误(如Chrome开发者控制台中所示):

system.src.js:4681 GET http://localhost:3000/rxjs/Subject 404 (Not Found)F @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681
system.src.js:4681 GET http://localhost:3000/rxjs/observable/fromPromise 404 (Not Found)F @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681
localhost/:1 Uncaught (in promise) Error: XHR error (404 Not Found) loading http://localhost:3000/rxjs/Subject(…)t @ system.src.js:4681g @ system.src.js:4681(anonymous function) @ system.src.js:4681
system.src.js:4681 GET http://localhost:3000/rxjs/operator/toPromise 404 (Not Found)F @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681(anonymous function) @ system.src.js:4681
system.src.js:4681 GET http://localhost:3000/rxjs/Observable 404 (Not Found)

我已经RxJS在我的package.json文件(^ 5.0.0-beta.0)中,它已经安装了npm,但问题是我现在还不熟悉,SystemJS以便让事情运行起来.这是我index.html文件中的正文部分:


 









我一直在玩其他配置,但没有一个让我一路走来.我的猜测是,这是相对简单的,只是我缺乏理解或工具的使用方式阻止了我.

这是我的app.ts文件,它是app/appSystemJS配置中引用的:

import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {COMMON_DIRECTIVES} from 'angular2/common';

@Component({
    selector: 'app',
    directives: [],
    template: `
{{greeting}}, world!
` }) export class App { greeting:string = 'Hello'; } bootstrap(App, [COMMON_DIRECTIVES]);

我正在使用一个Express使用静态映射的livereload 服务器为应用程序提供服务,这样http://localhost:3000/node_modules/rxjs/Rx.js即使作为服务器的根目录index.html提供所需的文件也能够获得所需的文件/src,并且node_modules实际上处于同一级别src而不是在其中.

任何帮助都将一如既往地受到赞赏.



1> Michael Oryl..:

事实证明,通过将SystemJS配置更改为我的index.html文件中的以下内容,可以轻松解决问题:

System.config({
    map: {
        rxjs: 'node_modules/rxjs' // added this map section
    },
    packages: {
        'app': {defaultExtension: 'js'},
        'rxjs': {defaultExtension: 'js'} // and added this to packages
    }
});
System.import('app/app');

我实际上已经尝试过,但是我没有意识到这一点,zone.js并且reflect-metadata也不再包含在Angular 2中,我也遇到了这个问题.

对于那些感兴趣的人,我通过在index.html中包含该文件来解决缺乏zone.jsreflect-metadata最容易的问题angular2-polyfills.js:


现在我的应用程序就像使用Alpha 53一样.

推荐阅读
谢谢巷议
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有