LoginSignup
0
0

More than 5 years have passed since last update.

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

Last updated at Posted at 2017-07-27

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"
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0