首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >金色布局与角6使用打字稿?

金色布局与角6使用打字稿?
EN

Stack Overflow用户
提问于 2018-10-17 17:23:13
回答 2查看 3.9K关注 0票数 5

我使用的是角度为6的黄金版面,遵循本教程

我在GoldenLayoutModule.forRoot(config)上有个错误

配置不能分配给GoldenLayoutConfiguration类型的参数。

代码语言:javascript
复制
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 { }
EN

回答 2

Stack Overflow用户

发布于 2018-10-18 19:59:44

通过将黄金布局实例的javascript文件转换为类型记录,我获得了使用角6的黄金布局。我包括我的角6文件为这个例子,以便其他人可以开始一个完整的工作例子,以节省他们的时间,我已经花了。我不知道为什么Ng6-黄金布局没有工作,因为它应该是兼容的角度6,但无法得到布局配置语法,并没有找到任何完整的工作例子在我的搜索。

首先,必须安装一个软件包:

代码语言:javascript
复制
npm install --save golden-layout@1.5.9 jquery

与角6兼容的文件如下:

app.module.ts

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
 <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" />
票数 4
EN

Stack Overflow用户

发布于 2018-10-17 17:56:08

config需要类型为GoldenLayoutConfiguration。看起来像这条线

代码语言:javascript
复制
let config = {

是你的问题。试试这个:

代码语言:javascript
复制
let config:GoldenLayoutConfiguration = {

文档说:

代码语言:javascript
复制
myLayout = new GoldenLayout({
  content:[{ 
    type: 'component', 
    componentName: 'sayHi',
    componentState: { name: 'Wolfram' }
  }]
});

所以这是你可以尝试的东西。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52860451

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档