如何将不可变的js导入angular 2(alpha)

How do I import immutable js into angular 2 (alpha)?

本文关键字:angular alpha 导入 js 不可变      更新时间:2023-09-26

我尝试过:

import {Component, Template, bootstrap} from 'angular2/angular2';
import {Immutable} from 'immutable/immutable';
@Component({
  selector: 'my-app'
})
@Template({
  inline: '<h1>Hello {{ name }}</h1>'
})
class MyAppComponent {
  constructor() {
    this.name = 'Alice';
    this.wishes = Immutable.List(['a dog', 'a balloon', 'and so much more']);
    console.log(this.wishes);
  }
}
bootstrap(MyAppComponent);

但随后"不可更改"最终被定义。然后我尝试了:

import {Component, Template, bootstrap} from 'angular2/angular2';
import {Immutable} from 'immutable/immutable';
@Component({
  selector: 'my-app'
})
@Template({
  inline: '<h1>Hello {{ name }}</h1>'
})
class MyAppComponent {
  constructor(im: Immutable) {
    this.name = 'Alice';
    this.wishes = im.List(['a dog', 'a balloon', 'and so much more']);
    console.log(this.wishes);
  }
}

但后来我得到了Cannot resolve all parameters for MyAppComponent。有人能帮我吗?是的,我已经将immutable文件夹添加到了System.paths中。难道Immutable就是不能以ES6的方式导入吗?

这是一个小错误。我不得不更换
import {Immutable} from 'immutable/immutable';

import Immutable from 'immutable/immutable';