Angular 7 Observable:main.73926b0c96716431d554.js:1错误错误:未捕获(承诺):ReferenceError:rxjsSubscription未定义

时间:2019-03-27 14:20:42

标签: angular rxjs observable

请注意,只有在我构建应用程序并从服务器运行它时,该错误才发生。如果我在本地主机上运行,​​那就很好了。

我正在使用以下库:

"dependencies": {
"@angular/animations": "~7.2.5",
"@angular/common": "~7.2.5",
"@angular/compiler": "~7.2.5",
"@angular/core": "~7.2.5",
"@angular/forms": "~7.2.5",
"@angular/http": "~7.2.5",
"@angular/platform-browser": "~7.2.5",
"@angular/platform-browser-dynamic": "~7.2.5",
"@angular/router": "~7.2.5",
"@ngrx/effects": "^6.0.1",
"@ngrx/store": "^6.0.1",
"ace-builds": "^1.3.3",
"admin-lte": "^2.4.8",
"angular2-draggable": "^2.0.0-beta.2",
"autobahn": "^18.3.2",
"bootstrap": "^3.3.7",
"bootstrap-colorpicker": "^2.5.2",
"core-js": "^2.6.5",
"datatables.net": "^1.10.19",
"datatables.net-bs": "^1.10.19",
"datatables.net-fixedcolumns": "^3.2.6",
"datatables.net-fixedcolumns-bs": "^3.2.6",
"datatables.net-fixedheader": "^3.1.5",
"datatables.net-fixedheader-bs": "^3.1.5",
"datatables.net-select": "^1.2.7",
"datatables.net-select-bs": "^1.2.7",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"jquery-slimscroll": "^1.3.8",
"msgpack-lite": "^0.1.26",
"ng2-dragula": "^2.0.1",
"ngrx-store-localstorage": "^5.0.0",
"ngrx-store-logger": "^0.2.2",
"plotly.js": "^1.39.3",
"primeicons": "^1.0.0-beta.9",
"primeng": "^6.0.0",
"reselect": "^3.0.1",
"rxjs": "5.6.0-forward-compat.5",
"select2": "^4.0.6-rc.1",
"three": "^0.101.1",
"three-orbit-controls": "^82.1.0",
"three-ply-loader": "^1.0.0",
"three-stl-loader": "^1.0.6",
"zone.js": "^0.8.29"


},
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.6.8",
    "@angular/cli": "~7.3.1",
    "@angular/compiler-cli": "~7.2.5",
    "@angular/language-service": "~7.2.5",
    "@types/autobahn": "^0.9.39",
    "@types/jasmine": "^2.8.16",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^10.12.26",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.4",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.1",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.4.2",
    "rxjs-tslint": "^0.1.5",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.2.4"
  }

以及我的组件之一中的以下代码:

import { Observable, Subscription as rxjsSubscription, combineLatest, 
merge } from 'rxjs';

@Component({
    templateUrl: './file-exchange.component.html',
    styleUrls: ['./file-exchange.component.scss']
})
export class FileExchangeComponent implements OnInit, OnDestroy {

...

rxjsSubscriptions: rxjsSubscription = new rxjsSubscription();

...

ngOnInit(): void {

// Storage space subscription
    this.rxjsSubscriptions.add(
        this.store.select(root.fileXSpace)
            .subscribe((space: { bytesAllowed: number, bytesUsed: number }) => {
                this.bytesAllowed = space.bytesAllowed;
                this.bytesUsed = space.bytesUsed;
                // Careful not to do division by zero
                this.bytesPercentage = space.bytesAllowed > 0 ? 100 * space.bytesUsed / space.bytesAllowed : 0;
            })
    );

它可与Angular 6一起使用,但由于我已升级到angular 7而不再可用,收到以下错误:

  

main.73926b0c96716431d554.js:1错误错误:未捕获(承诺):ReferenceError:rxjsSubscription未定义   ReferenceError:未定义rxjsSubscription       在新的CA(main.73926b0c96716431d554.js:1)       在wv(main.73926b0c96716431d554.js:1)       在bv(main.73926b0c96716431d554.js:1)       在合资企业(main.73926b0c96716431d554.js:1)       在Yv(main.73926b0c96716431d554.js:1)       在Wy(main.73926b0c96716431d554.js:1)       在Object.my [作为createRootView](main.73926b0c96716431d554.js:1)       在Hg.create(main.73926b0c96716431d554.js:1)       在ws.create(main.73926b0c96716431d554.js:1)       在qg.createComponent(main.73926b0c96716431d554.js:1)       在j(polyfills.57411ef973d8af233f6e.js:1)       在j(polyfills.57411ef973d8af233f6e.js:1)       在polyfills.57411ef973d8af233f6e.js:1       在e.invokeTask(polyfills.57411ef973d8af233f6e.js:1)       在Object.onInvokeTask(main.73926b0c96716431d554.js:1)       在e.invokeTask(polyfills.57411ef973d8af233f6e.js:1)       在t.runTask上(polyfills.57411ef973d8af233f6e.js:1)       在y(polyfills.57411ef973d8af233f6e.js:1)       在t.invokeTask上[调用时](polyfills.57411ef973d8af233f6e.js:1)       在_(polyfills.57411ef973d8af233f6e.js:1)

我尝试更改库“ rxjs”的版本:“ 5.6.0-forward-compat.5”,如一些帖子(5、6.2.1、6.4以及更多文章)所建议的那样,但错误只是不会消失。

很抱歉重复我的讲话,但我想确保能看到以下消息:

请注意,只有在我构建应用程序并从服务器运行它时,该错误才发生。如果我在本地主机上运行,​​那就很好了。

1 个答案:

答案 0 :(得分:1)

尝试使用此代码:

import { Observable, Subscription, combineLatest, merge } from 'rxjs';

rxjsSubscriptions: Subscription[] = [];

this.rxjsSubscriptions.push(
    //
);

ngOnDestroy() {
   this.rxjsSubscriptions.forEach(sub => sub.unsubscribe());
}