【发布时间】:2017-05-02 21:57:23
【问题描述】:
我正在尝试使用 Angular 2 编写 Chrome 扩展程序。
在我的app.component.ts 中,我有以下内容:
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html'
})
export class AppComponent {
showHeading = true;
heroes = ['Magneta', 'Bombasto', 'Magma', 'Tornado'];
toggleHeading() {
this.showHeading = !this.showHeading;
}
injectHello(){
chrome.runtime.sendMessage({action:"inject"});
}
}
问题是当我尝试使用Ahead of Time compilation 进行编译时,我得到了这个错误:
/dev/quickstart/app/app.component.ts:14:12 处的错误: 类型“typeof chrome”上不存在属性“runtime”。
显然,我的 Angular 应用程序不了解 chrome.runtime。解决此问题的最佳方法是什么?
我已经看到 this stack overflow answer 关于使用 tsc 编译 chrome-app.d.ts,但我需要使用 Ahead of Time compilation 来绕过内容安全策略。
因此,我使用node_modules/.bin/ngc -p tsconfig-aot.json 而不是tsc。有什么帮助吗?
【问题讨论】:
标签: angular typescript google-chrome-extension