/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
devtools/projects/ng-devtools/src/lib/devtools-tabs/profiler/file-api-service.ts
41 строка
1 KB
Kristiyan Kostadinov
fix(devtools): fix type checking issues (#60481)
20 мар 2025, 21:55
20 мар 2025, 21:55
e301471
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {Injectable} from '@angular/core'; import {Subject} from 'rxjs'; @Injectable({ providedIn: 'root', }) export class FileApiService { uploadedData: Subject<any> = new Subject(); publishFileUpload(parentEvent: Event): void { const reader = new FileReader(); reader.onload = (event) => { try { this.uploadedData.next(JSON.parse((event.target as any).result)); } catch (e) { this.uploadedData.next({error: e}); } (parentEvent.target as any).value = ''; }; reader.readAsText((parentEvent.target as any).files[0]); } saveObjectAsJSON(object: object): void { const downloadLink = document.createElement('a'); const isoString = new Date().toISOString().slice(0, -5); // remove milliseconds downloadLink.download = `NgDevTools-Profile-${isoString}.json`; downloadLink.href = URL.createObjectURL( new Blob([JSON.stringify(object)], {type: 'application/json'}), ); downloadLink.click(); setTimeout(() => URL.revokeObjectURL(downloadLink.href)); } }