我正在构建 Chrome 应用。该应用程序是使用 TypeScript (Angular2) 编写的。
我想推送通知。这是代码:
import {Injectable} from 'angular2/core';
@Injectable()
export class NotificationService {
constructor() {
if(Notification.permission !== 'granted') {
Notification.requestPermission();
}
}
}
当 gulp 构建应用程序时,它说:
src/scripts/stream/notification.service.ts(6) Cannot find name 'Notification'.
我试图将我的类(class)包装在里面:
/* tslint:disable */
... the code
/* tslint:enable */
但这并没有改变任何东西。
有没有办法通过 tslint.json 文件告诉 Typescript 这是一个全局变量?
使用 jshint 会是这样的:
"globals": {
"Notification": false
}
最佳答案
这里有几个选项:
关于push-notification - TypeScript 和 Chrome 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34617674/