Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

How to add Web Animations API polyfill to an Angular 2 project created with Angular CLI

The Angular 2 animations documentation refers to the Web Animations API polyfill for browsers that don't support the native one.

What's the proper way to add this polyfill to an Angular 2 project created with Angular CLI?

(I am using angular-cli: 1.0.0-beta.10)

With no luck, I have tried the ideas and solutions mentioned here:

I downloaded it via NPM and added it to system-config.ts. I believe this is along the lines of what's recommended but the polyfill doesn't get loaded (I can tell because the animations don't work in Safari).

I only got this to work by including the polyfill in index.html, which I know it's not the proper way:

  <script src="https://rawgit.com/web-animations/web-animations-js/master/web-animations.min.js"></script>

I will add here any details that may help clarify my question, but if you need to see the code, I have it on Github:

https://github.com/cmermingas/connect-four

Thanks in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Adding the polyfill with the newer, Webpack version of Angular CLI is easier:

  1. Install with npm install web-animations-js --save

  2. Add to polyfills.ts: require('web-animations-js/web-animations.min');

It also worked if I do import 'web-animations-js/web-animations.min';


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...