typescript - 使用 typescript 的 Angular 6 的黄金布局?

标签 typescript angular6 golden-layout

我正在使用 golden layout使用 Angular 6,关注 this tutorial .

我在 GoldenLayoutModule.forRoot(config) 上遇到错误

config not assignable to parameter of type GoldenLayoutConfiguration.

import { AppComponent } from './app.component';
import { GoldenLayoutModule, GoldenLayoutConfiguration } from '@embedded-enterprises/ng6-golden-layout';
import * as $ from 'jquery';

// It is required to have JQuery as global in the window object.
window['$'] = $;

// const config: GoldenLayoutConfiguration { /* TODO */ };


let config = {
  content: [{
      type: 'row',
      content:[{
          type: 'component',
          componentName: 'testComponent',
          componentState: { label: 'A' }
      },{
          type: 'column',
          content:[{
              type: 'component',
              componentName: 'testComponent',
              componentState: { label: 'B' }
          },{
              type: 'component',
              componentName: 'testComponent',
              componentState: { label: 'C' }
          }]
      }]
  }]
};

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    GoldenLayoutModule.forRoot(config)
  ],
  entryComponents: [
    // TODO Add your components which are used as panels in golden-layout also here.
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

最佳答案

通过转换 golden-layout example 的 javascript 文件,我能够获得与 Angular 6 一起使用的黄金布局。 typescript 。我为这个例子包含了我的 angular 6 文件,这样其他人就可以从一个完整的工作例子开始,以节省他们花费的时间。我不确定为什么 ng6-golden-layout 不起作用,因为它应该与 Angular 6 兼容,但无法获得布局配置语法,并且在我的搜索中找不到任何完整的工作示例。

首先,必须安装一个包:

npm install --save golden-layout@1.5.9 jquery

与 Angular 6 兼容的文件如下:

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import * as $ from 'jquery';

// It is required to have JQuery as global in the window object.
window['$'] = $;

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule
  ],
  entryComponents: [
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts

import { Component } from '@angular/core';
import * as GoldenLayout from 'golden-layout';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  myLayout: GoldenLayout;
  title = 'popout-ex';

  config:any = {
    content: [{
      type: 'row',
      content: [
          {
          type:'component',
          componentName: 'example',
          componentState: { text: 'Component 1' }
          },
        {
          type:'component',
          componentName: 'example',
          componentState: { text: 'Component 2' }
          },
        {
          type:'component',
          componentName: 'example',
          componentState: { text: 'Component 3' }
          }
      ]
    }]
  };

  ngOnInit() {
      this.myLayout = new GoldenLayout( this.config );

      this.myLayout.registerComponent( 'example', function( container, state ){
        container.getElement().html( '<h2>' + state.text + '</h2>');
      });

      this.myLayout.init();
    }
}

app.component.html

 <link type="text/css" rel="stylesheet" href="//golden-layout.com/assets/css/goldenlayout-base.css" />
 <link type="text/css" rel="stylesheet" href="//golden-layout.com/assets/css/goldenlayout-dark-theme.css" />

关于typescript - 使用 typescript 的 Angular 6 的黄金布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52860451/

相关文章:

javascript - 在 Angular Material 中选择 mat-option 时调用 ngmodelchange

css - 具有响应式内容设计的黄金布局

angular - 删除 dcl-wapper angular2 中扭曲的动态组件

javascript - 当我调用异步函数时等待返回未定义?

angular - 当以 5/6 Angular Angular 单击按钮时,如何从 url 下载文件

javascript - 当 Webview 元素移动到包含 DOM 时防止 Electron 的 WebView 重新加载的方法

在 axis.tickFormat() 中使用 d3.timeFormat 时出现 TypeScript 错误

typescript - typescript 中的 Pick<T, "properties"> 和 T ["properties"] 有什么不同

angular - 如何始终将焦点设置在 Angular 中的输入上