
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
ngx-golden-layout
Advanced tools
[](https://www.npmjs.com/package/ngx-golden-layout) [](https://www.npmjs.com/package/ngx-golden-layout) [,
],
declarations: [
// Add your panel components here
MyFancyAngularComponent,
],
})
export class AppModule {}
In the @NgModule
decorator, under entryComponents
list all the components that should be rendered within golden layout.
To pass a layout into the golden-layout component, create an Observable<IExtendedGoldenLayoutConfig>
and pass your layout/root config in.
Example code could look like this:
import { of } from 'rxjs';
const INITIAL_LAYOUT: IExtendedGoldenLayoutConfig = {
content: [{
type: 'row',
content: [{
type: 'component',
componentName: 'name', // The name defined in componentTypes
title: 'CustomTitle',
}, {
type: 'component',
componentName: 'name', // The name defined in componentTypes
title: 'Another Name',
}]
}]
};
@Component({
template: `<div class="spawn-new"></div><golden-layout-root [layout]="layoutConfig$"></golden-layout-root>`,
selector: `app-root`,
})
export class RootComponent {
layoutConfig$ = of(INITIAL_LAYOUT);
}
Finally import GoldenLayout styles into styles.css
@import "~golden-layout/src/css/goldenlayout-base.css";
@import "~golden-layout/src/css/goldenlayout-light-theme.css";
body, html {
width: 100vw;
height: 100vh;
padding: 0;
margin: 0;
}
After that it should work right away out of the box.
The original GoldenLayout API may be obtained through the Angular dependency injection mechanism in any of the components rendered with GoldenLayout.
import * as GoldenLayout from 'golden-layout';
import { Component, Inject } from '@angular/core';
import {
GoldenLayoutContainer,
GoldenLayoutComponentHost,
GoldenLayoutComponent,
} from '@embedded-enterprises/ng6-golden-layout';
@Component({})
export class TestComponent {
constructor(
@Inject(GoldenLayoutComponentHost) private goldenLayout: GoldenLayoutComponent,
@Inject(GoldenLayoutContainer) private container: GoldenLayout.Container
) {
this.goldenLayout.getGoldenLayout().selectItem(yourItem);
}
}
These objects can then be used to manipulate the GoldenLayout. Important: You must not cache the returned golden layout instance, as it might change as you pop out/in.
To get a deeper understanding on how to hook into golden layout and angulars behavior, refer to LIFECYCLE.md
When you use angular routing, angular will manipulate the URLs on the client side and therefore destroy navigation for your application when you're opening a popout. The solution is fairly simple: we disable the angular routing functionality for child windows.
Let's assume your project looks like the following:
root
|->src
| |-> main.ts
| |-> index.html
| |-> app
| | |-> app.module.ts
| | |-> login.component.ts
| | |-> main.component.ts
| | x
| x
|-> angular.json
x
Basically we need to implement three things:
To proceed, we need the following information:
<app-main>
)<app-docking>
)<app-main>
)if (!window.opener) {
const baseRootElem = document.createElement('app-main');
const script = document.body.querySelector('script');
document.body.insertBefore(baseRootElem, script);
platformBrowserDynamic().bootstrapModule(AppModule);
} else {
const baseAppElem = document.createElement('app-docking');
const script = document.body.querySelector('script');
document.body.insertBefore(baseAppElem, script);
platformBrowserDynamic().bootstrapModule(AppChildWindowModule);
}
<app-main>
component is set as bootstrap.<app-docking>
component as bootstrap.const COMPONENTS = [
AppDockingComponent,
// Your dockable components,
];
@NgModule({
declarations: COMPONENTS,
exports: COMPONENTS,
imports: [CommonModule, GoldenLayoutModule.forRoot(CONFIG), /* Additional modules */],
})
export class AppComponentsModule {}
@NgModule({
imports: [RouterModule.forRoot(ROUTES), AppComponentsModule],
declarations: [AppMainComponent],
entryComponents: [AppMainComponent],
providers: [
// Your providers
],
bootstrap: [AppMainComponent],
})
export class AppModule { }
@NgModule({
imports: [AppComponentsModule],
providers: [
// Your providers
],
bootstrap: [AppDockingComponent], // Use your docking component here.
})
export class AppChildWindowModule { }
useHash: true
in your call to RouterModule.forRoot(ROUTES, { useHash: true })
projects -> $NAME -> architect -> build -> configurations -> production -> fileReplacements
:{
"replace": "src/main.ts",
"with": "src/main.prod",
}
src/main.ts
into src/main.prod
(Don't name main.prod
main.prod.ts
otherwise you will get build errors!)platformBrowserDynamic
by platformBrowser
platform-browser-dynamic
by platform-browser
bootstrapModule
by bootstrapModuleFactory
AppModule
by AppModuleNgFactory
AppChildWindowModule
by AppChildWindowModuleNgFactory
app.module
by app.module.ngfactory
The effect of the changes done above is that we skip routing based on whether we're in a child window (no routing) or in the main window. When the route changes and the golden layout main-window component is destroyed, all child windows are disposed automatically.
To see a full-featured example including routing, have a look here.
All services used within your app can be chosen to be either scoped to the current window (default) or to be the same instance across all windows (like a singleton).
To synchronize a service, use the @MultiWindowService()
decorator:
@MultiWindowService<YourService>()
@Injectable()
class YourService {
// implementation
}
NOTE: This only works once per service instance, it will destroy scoped services!
If you want to remove a component type, but don't want your users to clear the entire state, you can use the fallback component.
It works by creating a component, like this:
import { FailedComponent } from '@embedded-enterprises/ng6-golden-layout';
@Component({
selector: `app-invalid`,
template: `<h1>Component {{componentName}} couldn't be found`,
})
class InvalidComponent {
// The InjectionToken `FailedComponent` provides the name of the failed component.
// You can use this to implement arbitrarily complex error pages.
constructor(@Inject(FailedComponent) public componentName: string) { }
}
After that, you pass the Component Type into the GoldenLayout.forRoot function like this:
// In your main NgModule
@NgModule({
imports: [
GoldenLayoutModule.forRoot(COMPONENTS, InvalidComponent),
],
declarations: [
//...
InvalidComponent,
],
})
export class MyModule { }
When you have setup this, the binding will automatically create this component whenever a panel type couldn't be found.
With this module it is possible to initialize nested instances of golden-layout. Therefore you can have several different, independent docking steps.
To use it, call GoldenLayoutModule.forChild()
within the providers array of a nested component in your application and initialize
a new GoldenLayoutComponent.
@Component({
selector: 'app-nested-gl',
templateUrl: './nested.component.html',
styleUrls: ['./nested.component.scss'],
providers: [
GoldenLayoutModule.forChild(components),
]
})
export class NestedComponent implements OnInit {
public layout$ = new BehaviorSubject(LAYOUT_CONFIG);
constructor() { }
ngOnInit(): void { }
stateChange() {
}
tabActivated() {
}
Template:
<golden-layout-root #comp [layout]="layout$" (stateChanged)="stateChange()" (tabActivated)="tabActivated($event)"></golden-layout-root>
This binding is stable but by far not feature complete.
build.sh
or npm run build
to create the npm package and link it into the example project.Contributions are welcome!
FAQs
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.0.0.
The npm package ngx-golden-layout receives a total of 115 weekly downloads. As such, ngx-golden-layout popularity was classified as not popular.
We found that ngx-golden-layout demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.