我使用JSPM和SystemJS设置了我的Angular2项目 . 我尝试在我的 boot.ts
文件中导入 RxJS
和一些运算符,但我的导入不会被转换为 boot.js
输出 . 所以
// boot.ts
import {Observable} from 'rxjs/Observable'
import 'rxjs/add/operator/debounceTime'
...
如下所述:https://github.com/ReactiveX/RxJS#es6-via-npm最终为
// boot.js
System.register(['rxjs/add/operator/debounceTime', ...
tsc
(尝试过1.7.5和1.8.0):
// tsconfig.json
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": true,
"noImplicitAny": false,
"module": "system",
"moduleResolution": "node",
"rootDir": "src",
"target": "es5"
}
, "exclude": [
"jspm_packages",
"node_modules",
"typings/main.d.ts",
"typings/main"
]
}
我错过了什么?
UPDATE
如果稍后在代码中使用TypeScript,则TypeScript将仅导入 emit
. 我只需要额外的运算符来监听Angular2 control
的 valueChanges
observable . 但是,如果缺少 rxjs
的 Observable
类,则无法修补其他运算符 . 所以你需要通过这样的导入强制TypeScript到 emit
System.register
for Observable
:
// boot.ts
import 'rxjs/Observable'
import 'rxjs/add/operator/debounceTime'
...
所有的功劳归功于@RyanCavanaugh,他指出了我正确的方向 .
2 回答
成功解决问题的评论的答案:
import 'rxjs/Observable'
参考:https://github.com/Microsoft/TypeScript/wiki/FAQ#why-are-imports-being-elided-in-my-emit
您需要以正确的方式导入Observable类:
如果要在同一时间包含所有运算符,请执行以下操作: