微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

javascript – 以一种所有函数都可以访问它的方式声明角度变量

参见英文答案 > 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
                
                                 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐