Golden Layout с Angular 6, используя машинопись? - PullRequest
0 голосов
/ 17 октября 2018

Я использую золотой макет с Angular 6, после этого урока .

Я получаю сообщение об ошибке GoldenLayoutModule.forRoot(config)

config не может быть назначен параметру типа 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 { }

Ответы [ 2 ]

0 голосов
/ 18 октября 2018

Мне удалось заставить золотой макет работать с Angular 6, преобразовав файл javascript из примера золотого макета в машинописный текст.Я включил мои угловые 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" />
0 голосов
/ 17 октября 2018

config должно быть типа GoldenLayoutConfiguration.Похоже, эта строка

let config = {

является вашей проблемой.Попробуйте это:

let config:GoldenLayoutConfiguration = {

Документация гласит:

myLayout = new GoldenLayout({
  content:[{ 
    type: 'component', 
    componentName: 'sayHi',
    componentState: { name: 'Wolfram' }
  }]
});

, так что вы можете попробовать еще кое-что.

...