ngx-dynamic-json-form-material
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

ngx-dynamic-json-form-material

The easy way to generate JSON based forms with angular.

Quick Start

This is the UI material package for ngx-dynamic-json-form.

Without ngx-dynamic-json-form-core this library is not usable. So please take care to install it too.

Versions

Angular Angular Material ngx-dynamic-json-form-core ngx-dynamic-json-form-material
< 15 < 15 not tested, if it is working, please report it via GitHub. not tested, if it is working, please report it via GitHub.
> 15.x.x > 15.x.x 1.x.x 1.x.x

Install and Usage

This is a step by step instruction to install and use ngx-dynamic-json-form-material.

1. Install all packages:

npm i ngx-dynamic-json-form-core ngx-dynamic-json-form-material ngx-mat-select-search --save

Please make sure, that @angular/forms and "@angular/material are already installed.

2. Add ngx-dynamic-json-form-material

The forRoot() method call is required on root level.

This method is used to override default configurations and is needed to register custom components.

More information can be found in the global configuration section in the docs.

2.1. to your AppModule (Module based)

import { NgxDynamicJsonFormMaterialModule } from "ngx-dynamic-json-form-material";

@NgModule({
  imports: [
    // ...
    NgxDynamicJsonFormMaterialModule.forRoot(),
  ],
  // ...
})
export class AppModule {}

2.2. to your appConfig.ts (Standalone Version)

import { NgxDynamicJsonFormMaterialModule } from "ngx-dynamic-json-form-material";

export const appConfig: ApplicationConfig = {
  providers: [
    importProvidersFrom(NgxDynamicJsonFormMaterialModule.forRoot()),
    // ...
  ],
};

Hint: Don't forget to add NgxDynamicJsonFormMaterialModule in your standalone component as well.

import { NgxDynamicJsonFormMaterialModule } from "ngx-dynamic-json-form-material";

@Component({
  // ...
  standalone: true,
  imports: [CommonModule, NgxDynamicJsonFormMaterialModule], // <- Must Have
  changeDetection: ChangeDetectionStrategy.OnPush, // <- Recommended
})
export class MyStandaloneComponent {
  // ...
}

3. Configure the form in the component TS

@Component({
  // ...
  changeDetection: ChangeDetectionStrategy.OnPush, // <- Recommended
})
export class MyComponent implements OnInit {
  public form: FormGroup = new FormGroup({}); // <- The form instance

  // The form fields
  public fields: FormField[] = [
    {
      type: "select",
      key: "language",
      label: "Language",
      options: [
        { label: "Language 1", value: "1" },
        // ...
      ],
    },
  ];

  // The callback method to get the instance of the form
  public setForm(form: FormGroup): void {
    this.form = form;
  }
}

4. Use ngx-dynamic-json-form in the component HTML

<ngx-dynamic-json-form [fields]="fields" (getForm)="setForm($event)" [initial]="initialValues" formClassName="my-form-class"></ngx-dynamic-json-form>
Input Description Required
`fields` This is the configuration of all form fields. Yes
`getForm` A callback to get the instance of the `FormGroup`. No
`initial` An object with the initial values of the form. No
`formClassName` Add a class name to the form. No

Package Sidebar

Install

npm i ngx-dynamic-json-form-material

Weekly Downloads

6

Version

1.0.4

License

MIT

Unpacked Size

1.16 MB

Total Files

100

Last publish

Collaborators

  • digisolu