Using es6-shim in an Angular2/TypeScript project

荒凉一梦 提交于 2019-12-10 19:24:08

问题


I want to use es6's Map for an Angular2/typescript project. I guess the way to achieve that is through the es6-shim library. However I am really confused on how I am supposed to do that. Here is what I have done so far:

On my root index.html file I have this:

<script src="../node_modules/es6-shim/es6-shim.js"></script>

The above works just fine because if I run my app now it will load with no problems.

Then, in one of my typescript files I have this:

import * as shim from 'es6-shim/es6-shim.js';

If I do this I get an error when I try to run my application:

GET http://localhost:63342/gbkfitcloud_client/src/es6-shim/es6-shim 404 (Not Found)

Isn't this strange since I included es6-shim in my index.html?

Now, if I just manually copy the es6-shim.js file in the above directory it works, I don't get any errors.

Then, I try to create a Map object like this:

let foo = new shim.Map();

But I get the following error:

ORIGINAL EXCEPTION: TypeError: shim.Map is not a function

So, since I get these strange errors I assume that I am doing something totally wrong. Can someone help me please?

Thank you!

来源:https://stackoverflow.com/questions/34488074/using-es6-shim-in-an-angular2-typescript-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!