我有一个 navigator.share 的问题。我在 codepen 中测试了这段代码:if (navigator.share) { navigator.share({ title: 'Web Fundamentals', text: 'Check out Web Fundamentals — it rocks!', url: 'https://developers.google.com/web', }) .then(() => console.log('Successful share')) .catch((error) => console.log('Error sharing', error)); } else { console.log('no share'); }}https://codepen.io/cookienawer/pen/ZEzpYrW?editors=1010并在我的移动设备上工作。但是当我将此代码放入我的应用程序中时,Angular 不会进入 if。我也测试 canShare 方法,因为这是一个测试,但我想共享图像。带有标签的图像留在 DOM 中,但这是另一个问题......问题是我可以在 codepen 中共享任何东西,但不能在 Angular 应用程序中共享。我发现要在 angular 中使用导航器,我必须将此代码放在导航器之前:let varNavigator: any;varNavigator = window.navigator; if (varNavigator.share) { ...如果我直接执行 varNavigator.share 它会显示此错误:core.js:1427 ERROR TypeError: (intermediate value)(intermediate value).share is not a function at e._next (home.component.ts:299) at e.__tryOrUnsub (Subscriber.js:239) at e.next (Subscriber.js:186) at e._next (Subscriber.js:127) at e.next (Subscriber.js:91) at e.notifyComplete (ForkJoinObservable.js:197) at e._complete (InnerSubscriber.js:32) at e.complete (Subscriber.js:116) at e._complete (Subscriber.js:134) at e.complete (Subscriber.js:116)我从 URL 获取代码:https://developers.google.com/web/updates/2016/09/navigator-share https://developers.google.com/web/updates/2019/05/web-share-files
添加回答
举报
0/150
提交
取消