小编pra*_*eep的帖子

'Navigator'类型中不存在属性'share'

我需要在我的Ionic应用程序中使用WebShareAPI.

这是我在介绍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');
}
Run Code Online (Sandbox Code Playgroud)

但是,Typescript编译失败,并出现以下错误:

[11:31:11]  typescript: src/pages/channel_home/channel_home.ts, line: 89
            Property 'share' does not exist on type 'Navigator'.
Run Code Online (Sandbox Code Playgroud)

这里有一个可能的原因解释 DOM lib:添加对navigator.share的支持

但是,我想知道一些解决方法,特别是在我的Ionic应用程序中,以及在任何Angular或Typescript应用程序中使WebShareApi工作.

typescript ionic-framework angular

15
推荐指数
5
解决办法
5056
查看次数

标签 统计

angular ×1

ionic-framework ×1

typescript ×1