如何将Angle 2+应用程序集成到Openfin平台

时间:2018-09-03 13:10:12

标签: angular openfin

我需要在openfin中集成现有的angular 5应用程序(特别是使用wpf嵌入式视图)。我将需要使用Interapplication总线与嵌入式应用程序进行通信。我找不到如何将其集成到组件中的示例。

1 个答案:

答案 0 :(得分:0)

好-我终于明白了。

要做些什么才能使它正常工作。首先,通过包含@ types / openfin-npm包来告诉Typescript编译器有关类型的信息。您会注意到编辑器将开始在其智能感知中识别类型,但是在构建应用程序时,打字稿编译器将引发异常-'找不到名称'fin'。

要解决此问题,请打开tsconfig.json并确保其中包括:  1.整个@types文件夹位于typeroots中  2.在“类型”数组中查找类型。

{  ..    “ target”:“ es5”,     “ typeRoots”:[       “ node_modules / @ types”     ], ...   } }

更改后,应用程序应编译,没有任何打字稿错误。

现在,在您的应用程序组件中,您需要一种方法来查找该应用程序是否在开放鳍下运行。一旦fin变量可用,我们就可以使用InterApplication总线和所有其他openfin优点。一个基本的应用程序组件可能看起来像这样:-

    import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'test-ang';
  version: string;

  private _mainWin: fin.OpenFinWindow;

  constructor() {
    this.init();
  }

  init() {
    try {
      fin.desktop.main(() => this.initWithOpenFin());

    } catch (err) {
      this.initNoOpenFin();
    }
  };

  initWithOpenFin() {
    this._mainWin = fin.desktop.Window.getCurrent();

    fin.desktop.System.getVersion(function (version) {
      try {
        this.version = "OpenFin version " + version;
      } catch (err) {
        //---
      }
    });

  }

  initNoOpenFin() {
    alert("OpenFin is not available - you are probably running in a browser.");
  }

}