我正在构建 Angular8 PWA,并使用网络共享来共享文本,效果很好。\n自 2019 年 5 月起,Chrome 还支持\n文件共享
\n\n但是,尝试在 Typescript 中构建文件共享时遇到以下错误:
\n\nNotAllowedError:权限被拒绝
\n\nlet 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) 我在我的主要组件中发出了一个事件:
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.
我正在通过 Chrome 和 Service Worker 将通知推送到 Android 设备(7.0 和 8.1)。\n在 Service Worker 中,我正在创建如下通知:
\n\nconst 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});\nRun Code Online (Sandbox Code Playgroud)\n\n我愿意收到了通知并且它振动了,但无论我将什么数字放入模式常量(或直接将其放入振动),我总是会得到默认的振动模式(彼此之后有 2 个非常短的振动)。
\n\n我也尝试使用此处提供的示例,但总是得到相同的结果......只有 2 次非常短的振动)
\ntypescript ×2
angular ×1
eventemitter ×1
javascript ×1
navigator ×1
subscription ×1
vibration ×1