参见英文答案 > Angular 4/5/6 Global Variables 2个
我一遍又一遍地创建窗口变量我怎么能只声明一次呢?
我尝试将其添加到构造函数,但这不起作用.
import { Component } from '@angular/core';
import { ElectronService } from 'ngx-electron';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.sass']
})
export class AppComponent {
title = 'ae-test';
constructor(
private _ES: ElectronService,
) {}
minWindow() {
const window = this._ES.remote.getCurrentWindow();
window.minimize();
}
fullscreenWindow() {
const window = this._ES.remote.getCurrentWindow()
if (window.isFullScreen() == true) {
window.setFullScreen(false);
} else {
window.setFullScreen(true);
}
}
closeWindow() {
const window = this._ES.remote.getCurrentWindow();
window.minimize();
}
}
解决方法:
只需创建一个共享的单例服务
@Injectable()
export class GlobalService {
private _data = {value:0};
getData(){
return this._data; // get ref of the data object原文地址:https://codeday.me/bug/20190827/1744801.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。