标签:
Using TypeScript when installing packages from npm often requires you to install related definition files. This lesson shows you how to use typings to install es6-shim then how to configure SystemJS to load from node_modules.
Install:
npm install --save rxjs
Import:
import {Observable} from ‘rxjs/Observable‘;
import ‘rxjs/add/observable/interval‘;
But you will find errors, the reason for that rxjs include es6, but our target is es5.
So, install:
typings install es6-shim --save -ambient
Include:
<script> System.config({ packages: { "dist": { "defaultExtension": "js", "main": "main" }, "rxjs": { "defaultExtension": "js" } }, map: { "lodash": "https://npmcdn.com/lodash@4.13.1", "rxjs": "node_modules" } }); System.import("dist") </script>
Then you can start using rxjs;
import {Observable} from ‘rxjs/Observable‘; import ‘rxjs/add/observable/interval‘; Observable.interval(1000) .subscribe( x => console.log(x))
[TypeScript] Using Typings and Loading From node_modules
标签:
原文地址:http://www.cnblogs.com/Answer1215/p/5573085.html