[Angular] 关于处理 RxJS BehaviorSubject 读取错误的方法(疑问)
关于 RxJS BehaviorSubject 的实现方法
ERROR Error: Uncaught (in promise): TypeError:
BehaviorSubject_1.BehaviorSubject is not a constructor
TypeError: BehaviorSubject_1.BehaviorSubject is not a constructor
这个运行时错误我实在无法解决,尽管我进行了大量的调查和尝试,最终找到了一种避免的方法,但我不知道这是否是正确的实施方式…
运行时出现错误
import { Component } from "@angular/core";
import { BehaviorSubject } from "rxjs/BehaviorSubject";
@Component({
selector : "my-app",
template : `<h1>Hello World</h1>`,
})
export class MyAppComponent
{
private _isOpen: BehaviorSubject<boolean> = new BehaviorSubject(false);
constructor()
{
console.log(this._isOpen);
}
}
不会发生运行时错误。
import { Component } from "@angular/core";
import * as Rx from "rxjs";
@Component({
selector : "my-app",
template : "<h1>Hello World</h1>",
})
export class MyAppComponent
{
private _isOpen: Rx.BehaviorSubject<boolean> = new Rx.BehaviorSubject(false);
constructor()
{
console.log(this._isOpen);
}
}
系统配置文件 system.config.js
(中略)
const map = {
rxjs : "node_modules/rxjs",
} as {[key: string]: string};
(中略)
const packages = {
rxjs : { defaultExtension : "js", main : "bundles/Rx.js" },
} as {[key: string]: any};
(中略)
版本
{
"dependencies": {
"@angular/animations": "^4.3.1",
"@angular/common": "^4.3.1",
"@angular/compiler": "^4.3.1",
"@angular/compiler-cli": "^4.3.1",
"@angular/core": "^4.3.1",
"@angular/forms": "^4.3.1",
"@angular/http": "^4.3.1",
"@angular/platform-browser": "^4.3.1",
"@angular/platform-browser-dynamic": "^4.3.1",
"@angular/platform-server": "^4.3.1",
"@angular/router": "^4.3.1",
"reflect-metadata": "^0.1.10",
"rxjs": "^5.4.2",
"systemjs": "^0.20.16",
"zone.js": "^0.8.14"
}
}