简体   繁体   English

如何在 Angular 中使用 chrome 扩展?

[英]How to use chrome extension in Angular?

How can i use chrome in my angular app?In my app.module如何在我的 angular 应用程序中使用 chrome?在我的 app.module 中

export const CHROME = new InjectionToken('CHROME');

and

providers: [...{ provide: CHROME, useValue: window.chrome } ...],

In my service在我的服务

/// <reference types="chrome"/>
import { chrome } from '@types/chrome';
constructor(  @Inject(CHROME) private chrome: chrome) {
  }

But i have an error:但我有一个错误:

TS2306: File 'C:/Users/Sergey/Desktop/someProject/node_modules/@types/chrome/index.d.ts' is not a module. TS2306:文件“C:/Users/Sergey/Desktop/someProject/node_modules/@types/chrome/index.d.ts”不是模块。 TS6137: Cannot import type declaration files. TS6137:无法导入类型声明文件。 Consider importing 'chrome' instead of '@types/chrome'.考虑导入“chrome”而不是“@types/chrome”。

我不知道它有多正确,但它帮助了我:添加 .d.ts 文件,其中“declare let chrome”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM