加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – SystemJS为rxjs加载许多文件

发布时间:2020-12-17 07:56:40 所属栏目:安全 来源:网络整理
导读:我有以下systemjs.config.js(基于我在互联网上找到的一些例子): (function (global) { System.config({ paths: { // paths serve as alias 'js:': 'js/',},// map tells the System loader where to look for things map: { // our app is within the app f
我有以下systemjs.config.js(基于我在互联网上找到的一些例子):
(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'js:': 'js/',},// map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app: 'app',// angular bundles
            '@angular/core': 'js:angular2/core.umd.js','@angular/common': 'js:angular2/common.umd.js','@angular/compiler': 'js:angular2/compiler.umd.js','@angular/platform-browser': 'js:angular2/platform-browser.umd.js','@angular/platform-browser-dynamic': 'js:angular2/platform-browser-dynamic.umd.js','@angular/http': 'js:angular2/http.umd.js','@angular/router': 'js:angular2/router.umd.js','@angular/forms': 'js:angular2/forms.umd.js','@angular/upgrade': 'js:angular2/upgrade.umd.js',// other libraries
            'rxjs': 'js:rxjs','angular-in-memory-web-api': 'js:in-memory-web-api.umd.js'
        },// packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './main.js',defaultExtension: 'js'
            },rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

当我启动我的Angular2应用程序时,会加载许多单独的rxjs文件,这需要很长时间.我在js / rxjs / bundles / Rx.js中有一个捆绑版本的RxJ,所以我试着像这样修改systemjs.config.js:

(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'js:': 'js/',// other libraries
            'rxjs': 'js:rxjs/bundles/Rx.js',defaultExtension: 'js'
            }
        }
    });
})(this);

当我尝试立即启动我的应用程序时,我在浏览器中收到以下错误:

Error: (SystemJS) Syntax error
    SyntaxError: Syntax error
       at Anonymous function (eval code:2:1)
    Evaluating http://localhost:37191/js/rxjs/bundles/Rx.js/Subject
    Evaluating http://localhost:37191/app/main.js
    Error loading http://localhost:37191/app/main.js

我的main.ts看起来像这样:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

我的app.module.ts看起来像这样:

import 'rxjs';

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppRoutingModule } from './app-routing.module';

import { AppComponent } from './app.component';
import { DeviceGroupsViewComponent } from './device-groups-view.component';

import { DeviceGroupService } from './devicegroup.service';
import { SourceTypeService } from './sourcetype.service';

@NgModule({
    imports: [
        BrowserModule,FormsModule,HttpModule,AppRoutingModule
    ],declarations: [
        AppComponent,DeviceGroupsViewComponent
    ],providers: [
        DeviceGroupService,SourceTypeService
    ],bootstrap: [AppComponent]
})
export class AppModule { }

我需要更改什么才能使我的应用程序与捆绑的Rx.js一起使用?

如果您的设置基于angular2快速入门,那么您就可以了.

但是,你绝对不能

import {something} from 'rxjs/Rx';

这是错误的,将导入整个RxJS库(当您只想使用Observable时).

import {Observable} from 'rxjs/Rx';

这是对的

import {Observable} from 'rxjs/Observable';

并将减少进口数量.确保您的应用没有引用’rxjs / Rx’

PS你不想把整个RxJS库拉成一个文件,因为它会非常大.这就是仅导入您需要的RxJS模块的全部原因.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读