我有一个 Angular 2.0.0 (2.2.0 中有同样的问题)项目。当前的开发版本生成超过 100 个 http 请求。
这是因为它加载了非捆绑版本的 rxjs..
当我有以下情况时:
map: {
// our app is within the app folder
app: 'app',
// angular bundles
// snip
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
},
该应用程序可以工作,但我们有 1000 多个 http 请求,因此我尝试从捆绑包中加载 rxjs,为此我将其删除rxjs': 'npm:rxjs'
我添加以下内容
注意,对于 npm:从 unpkg 加载
paths: {
// paths serve as alias
'npm:': 'https://unpkg.com/',
'rxjs/*': 'https://unpkg.com/@reactivex/rxjs/dist/global/Rx.js'
},
ReactiveX git 页面表明这个包应该可以工作,还是缺少其他东西?
我在第二个配置中收到以下错误
Uncaught (in promise): TypeError: Cannot read property 'call' of undefined
我有一个 plnkr.io 演示,用于在 TypeScript 中摆弄 RxJS,它会像您一样加载捆绑版本。
See: http://plnkr.co/edit/0o9j6h5GJJiCuBFeWv7f http://plnkr.co/edit/0o9j6h5GJJiCuBFeWv7f
重要的部分是System.config
:
System.config({
transpiler: 'typescript',
map: {
'rxjs': 'https://unpkg.com/@reactivex/[email protected] /cdn-cgi/l/email-protection/dist/global/Rx.js'
}
});
然后从捆绑包中导入任何内容:
import {BehaviorSubject} from 'rxjs';
Edit:
默认的 Angular2 演示已更新为加载单个Rx.js
.
现场观看:http://plnkr.co/edit/rnO74mQNuPsHAmrIVJ8j http://plnkr.co/edit/rnO74mQNuPsHAmrIVJ8j
In systemjs.config.js
我删除了rxjs
form map
完全并添加到paths
:
'rxjs*': 'https://unpkg.com/@reactivex/[email protected] /cdn-cgi/l/email-protection/dist/global/Rx.js'
然后我将其用于例如:
import { Component } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Component({
selector: 'my-app',
template: '<h1>My First Angular App</h1>'
})
export class AppComponent {
constructor() {
console.log(BehaviorSubject);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)