TypeScript
angular
RxJS
Angular2

[angular] RxJS BehaviorSubject の読み込みエラーの対処法について(疑問)

More than 1 year has passed since last update.

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};
(中略)

vaersion

package.json
{
    "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"
    }
}