angular - 在 Angular 2 CLI 中使用 Smooth Scroll Polyfill

标签 angular angular-cli

任何人都可以指导如何将 Smooth Scroll Polyfill 与 Angular 2 CLI 一起使用。

我尝试在 polyfills.ts 中添加以下内容,但它会引发工作要求错误

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

然后我尝试添加

import 'smoothscroll-polyfill';

虽然它在构建期间没有抛出任何错误,但是当我在浏览器中运行项目时,它在控制台上显示以下错误:

ERROR TypeError: Failed to execute 'scroll' on 'Window': No function was found that matched the signature provided.

最佳答案

这是 Angular 2/4 解决方案:

安装 smoothscroll-polyfill - npm 安装 smoothscroll-polyfill

然后添加到你的 src/polyfills.ts 文件:

import smoothscroll from 'smoothscroll-polyfill/dist/smoothscroll.js';
smoothscroll.polyfill();

关于angular - 在 Angular 2 CLI 中使用 Smooth Scroll Polyfill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43175331/

相关文章:

angular - 如何针对远程服务器运行 ng e2e?

javascript - Angular 4 - 新的 MouseEvent 导致 IE11 错误

angular - 如何将照片上传到 Firebase 存储并在 Firestore 中插入照片 URL?

angular - "ionic cordova build android --prod --release"问题

angular - Ngx-Datatable 访问列中的 rowIndex

angular - Angular 类名中的自定义后缀

date - 如何在angular2中格式化日期?

angular - 当应用程序在外部服务器上运行时,所有请求均未找到(404)

angular - 从 angular 5 迁移到 angular 6 - @angular/core 的变化

Angular:通过环境设置 APP_BASE_HREF 无效