小编Ste*_*tef的帖子

打字稿权限中的 navigator.canShare() 被拒绝

我正在构建 Angular8 PWA,并使用网络共享来共享文本,效果很好。\n自 2019 年 5 月起,Chrome 还支持\n文件共享

\n\n

但是,尝试在 Typescript 中构建文件共享时遇到以下错误:

\n\n

NotAllowedError:权限被拒绝

\n\n
let navigator: any;\nnavigator = window.navigator;\nconst title = "myTitle";\nlet data = {\n  title: title,\n  text: text,\n  url: url,\n  files: []\n};\nconsole.log(data);\n\nif (navigator.share) {\n  fetch(url)\n    .then(res => res.blob()) \n    .then(file => {\n      const fileName = data.text + ".mp3";\n      const options = { type: "audio/mp3" };\n      const newFile = new File([file], fileName, options);\n      data.files.push(newFile);\n      console.log(data);\n//lastModified: 1564912016680\n//lastModifiedDate: Sun Aug 04 2019 11:46:56 GMT+0200 (Mitteleurop\xc3\xa4ische //Sommerzeit) {}\n//name: "myName.mp3"\n//size: 40643\n//type: "audio/mpeg"\n//webkitRelativePath: …
Run Code Online (Sandbox Code Playgroud)

google-chrome navigator typescript progressive-web-apps

6
推荐指数
1
解决办法
5758
查看次数

Angular 4发布和订阅共享服务中的事件

我在我的主要组件中发出了一个事件:

main.component.ts

this.sharedService.cartData.emit(this.data);
Run Code Online (Sandbox Code Playgroud)

这是我的sharedService.ts

import { Component, Injectable, EventEmitter } from '@angular/core';
export class SharedService {
    cartData = new EventEmitter<any>();
} 
Run Code Online (Sandbox Code Playgroud)

在我的其他(Sub)组件中,我想访问此值,但不知何故,订阅不起作用:

dashboard.ts

private myData: any;

constructor(private sharedService: SharedService) {
    this.sharedService.cartData.subscribe(
        (data: any) => myData = data,
        error => this.errorGettingData = <any>error,
        () => this.aggregateData(this.myData));
}
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?当我将数据作为Injectable传递时,它工作正常.在一些REST调用之后发生事件(在主组件中).

更新

所以问题是在第一次发射事件之后创建了子组件.我想在这种情况下最好直接将数据注入subcompnent.

subscription eventemitter typescript sharedservices angular

5
推荐指数
1
解决办法
4万
查看次数

Chrome 通知中的振动模式不适用

我正在通过 Chrome 和 Service Worker 将通知推送到 Android 设备(7.0 和 8.1)。\n在 Service Worker 中,我正在创建如下通知:

\n\n
const pattern = [500, 250, 500, 250, 500, 250, 500, 250, 500, 250, 500];\n\nself.registration.showNotification(title, {\n                    body: body,\n                    icon: \'img/icon_256.png\',\n                    badge: \'img/icon_256.png\',\n                    vibrate: pattern,\n                    tag: `ticket-${cartName}`,\n                    renotify: ticketsToShow.length > 0,\n                    actions: [{ action: \'overview\', title: \'\xc3\x9cbersicht \xc3\xb6ffnen\' }],\n                    data: { sessionId },\n});\n
Run Code Online (Sandbox Code Playgroud)\n\n

愿意收到了通知并且它振动了,但无论我将什么数字放入模式常量(或直接将其放入振动),我总是会得到默认的振动模式(彼此之后有 2 个非常短的振动)。

\n\n

我也尝试使用此处提供的示例,但总是得到相同的结果......只有 2 次非常短的振动)

\n

javascript notifications google-chrome vibration

5
推荐指数
1
解决办法
1360
查看次数