2

Been trying to add the smoothscroll-polyfill to my Angular 4 app built using the Angular CLI. Figured out it needs to go in polyfill.ts, but their docs indicate it needs to be added like:

require('smoothscroll-polyfill').polyfill() 

As does this StackOverflow answer, but Angular CLI throws an error saying require doesn't exist. I also tried to import it several different ways, but this didn't work either, for example:

import 'smoothscroll-polyfill/dist/polyfill.js'  

Any ideas how I might add this to my Angular 4 application?

Community
  • 1
  • 1
mtpultz
  • 17,267
  • 22
  • 122
  • 201
  • what version of the cli are you using? – Ahmed Musallam Apr 21 '17 at 21:09
  • I eventually found the answer. This is a duplicate question, but since it references Angular and not just ES6 I've marked it as duplicate instead of deleting it so anyone searching for the answer can find it more easily in case they focus their searches more on Angular and not ES6. – mtpultz Apr 21 '17 at 22:32

1 Answers1

0

I started a fresh angular-cli (v1.0.0)

  1. install the smoothscroll-polyfill dependency: npm install --save smoothscroll-polyfill
  2. in the file src/polyfills add this: import 'smoothscroll-polyfill';

I see the polyfill js file added when I ng serve

Ahmed Musallam
  • 9,523
  • 4
  • 27
  • 47
  • Hi, yah I can see it being loaded as well, and tried using `import`, but the the polyfill API isn't available for use on `window` - `window.scroll(...)` doesn't exist – mtpultz Apr 21 '17 at 22:01