【发布时间】:2018-05-29 15:04:47
【问题描述】:
我需要在我的 Ionic 应用程序中使用 WebShareAPI。
这是我在Introducing the Web Share API中建议的代码
if (window.navigator && window.navigator.share) {
window.navigator.share({
title: 'title',
text: 'description',
url: 'https://soch.in//',
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error));
} else {
alert('share not supported');
}
但是,Typescript 编译失败并出现以下错误:
[11:31:11] typescript: src/pages/channel_home/channel_home.ts, line: 89
Property 'share' does not exist on type 'Navigator'.
这里解释了一个可能的原因 DOM lib: add support for navigator.share
但是,我想知道一些解决方法,以使 WebShareApi 特别适用于我的 Ionic 应用程序,以及一般的任何 Angular 或 Typescript 应用程序。
【问题讨论】:
-
这已被添加到全局 dom 类型中:github.com/microsoft/TSJS-lib-generator/pull/837 但是,对我来说,在 Angular 9.1 中我仍然收到错误,这很奇怪。
标签: angular typescript ionic-framework