Skip to content

Generators

Creating and registering a new control, group or block and be cumbersome. To make this easier, ngx-formbar comes with three generator schematics.

All three schematics (control, group, block) support the same options:

OptionTypeRequiredDefault (control/group/block)Description
—keystringYesRegistration key used in the Formbar configuration.
—namestringNokeyBase name for component and interface.
—projectstringNoworkspace default projectAngular project name where files are generated.
—pathstringNocurrent working directoryPath to where the generated files will be placed.
—interfaceSuffixstringNoControl / Group / BlockSuffix appended to the interface name.
—componentSuffixstringNoControl / Group / BlockSuffix appended to the component class name.
—hostDirectiveHelperPathstringNo-Path to the the hostDirective helper, relative to the project root. If the file cannot be found or the option was not provided, it will fallback to using the verbose syntax.
—viewProviderHelperPathstringNo-Path to the the viewProvider helper, relative to the project root. If the file cannot be found or the option was not provided, it will fallback to using the verbose syntax.
—schematicsConfigstringNo-Path of the schematics configuration, relative to the project root, that is to be used by this schematic. If this parameter is left out, the schematic will try to resolve the file from its default location. Configuration set in this file will override all duplicate options passed to the CLI.
—skipRegistrationbooleanNofalseSkip automatic registration. You will have to register the component yourself or run the Register Scheamtic

The paths for hostDirectiveHelperPath and viewProviderHelperPath can have three different shapes, that all resolve differently.

These are the relevant default values:

  • Host Directive Helper File Name: (type).host-directive.ts
  • Host Directive Identifier: ngxfb(Type)HostDirective
  • View Provider Helper File Name: view-provider.ts
  • View Provider Identifier: viewProviders

Shape: path/to/helper/folder

This will resolve to the folder path and assumes the helper files are set up with the default names and identifiers.

If an index.ts exists, it will use this for the import. Otherwise, it falls back to importing from the helper file directly.

Shape: path/to/helper/folder/file-name.ts

This will resolve to the file path and assumes the helper files are set up with the default identifier.

If an index.ts exists, it will use this for the import. Otherwise, it falls back to importing from the helper file directly.

Shape: path/to/helper/folder/file-name.ts#customIdentifier

This will resolve to the file path and use the identifier as is. Make sure the spelling matches exactly that of the exported name

If an index.ts exists, it will use this for the import. Otherwise, it falls back to importing from the helper file directly.

Run:

Terminal window
ng generate @ngx-formbar/core:control --key <control-key> [--name <ComponentName>] [--project <project>] [--path <path>] [--interface-suffix <suffix>] [--component-suffix <suffix>]

This will:

  • Scaffold an interface <name><interfaceSuffix>.ts extending NgxFbControl.
  • Generate component files (<name><componentSuffix>.component.ts, .html, .scss, .spec.ts) wired with NgxfbControlDirective.
  • Register the new control in your Formbar configuration under componentRegistrations with the given key.

For implementation details and advanced usage, see the Controls Guide.

Run:

Terminal window
ng generate @ngx-formbar/core:group --key <group-key> [--name <ComponentName>] [--project <project>] [--path <path>] [--interface-suffix <suffix>] [--component-suffix <suffix>]

This will:

  • Scaffold an interface <name><interfaceSuffix>.ts extending NgxFbFormGroup.
  • Generate component files (<name><componentSuffix>.component.ts, .html, .scss, .spec.ts) wired with NgxfbGroupDirective.
  • Register the new group in your Formbar configuration under componentRegistrations with the given key.

For implementation details and advanced usage, see the Groups Guide.

Run:

Terminal window
ng generate @ngx-formbar/core:block --key <block-key> [--name <ComponentName>] [--project <project>] [--path <path>] [--interface-suffix <suffix>] [--component-suffix <suffix>]

This will:

  • Scaffold an interface <name><interfaceSuffix>.ts extending NgxFbBlock.
  • Generate component files (<name><componentSuffix>.component.ts, .html, .scss, .spec.ts) wired with NgxfbBlockDirective.
  • Register the new block in your Formbar configuration under componentRegistrations with the given key.

For implementation details and advanced usage, see the Blocks Guide.

There are two ways to set custom default options. This helps repeating the same parameters on every CLi command.

All options are optional, but are listed here in full. You can put any combination of them.

formbar.config.json
{
"controlRegistrationsPath": "app/form/registrations.ts",
"viewProviderHelperPath": "app/shared/helper/control-container.view-provider.ts",
"control": {
"interfaceSuffix":"Type",
"componentSuffix": "Input",
"hostDirectiveHelperPath":"app/form/helper",
"skipRegistration": true
},
"group": {
"interfaceSuffix":"GroupType",
"componentSuffix": "Group",
"hostDirectiveHelperPath":"app/form/helper",
"skipRegistration": true
},
"block": {
"interfaceSuffix":"BlockType",
"componentSuffix": "Block",
"hostDirectiveHelperPath":"app/form/helper",
"skipRegistration": true
}
}

You can set default values for any ngx-formbar schematic option in your angular.json. Add a schematics section under your project with the schematic name and desired defaults.

All options are optional, but are listed here in full. You can put any combination of them. Note, that compared to formbar.config.json, you have to repeat all values.

angular.json
{
"projects": {
"my-app": {
"schematics": {
"@ngx-formbar/core:control": {
"controlRegistrationsPath": "app/form/registrations.ts",
"viewProviderHelperPath": "app/shared/helper/control-container.view-provider.ts",
"interfaceSuffix":"Type",
"componentSuffix": "Input",
"hostDirectiveHelperPath":"app/form/helper",
"skipRegistration": true
},
"@ngx-formbar/core:group": {
"controlRegistrationsPath": "app/form/registrations.ts",
"viewProviderHelperPath": "app/shared/helper/control-container.view-provider.ts",
"interfaceSuffix":"GroupType",
"componentSuffix": "Group",
"hostDirectiveHelperPath":"app/form/helper",
"skipRegistration": true
},
"@ngx-formbar/core:block": {
"controlRegistrationsPath": "app/form/registrations.ts",
"viewProviderHelperPath": "app/shared/helper/control-container.view-provider.ts",
"interfaceSuffix":"BlockType",
"componentSuffix": "Block",
"hostDirectiveHelperPath":"app/form/helper",
"skipRegistration": true
}
}
}
}
}

Due to the current implementation and how the default values are set, the options are resolved in the following cascading order.

  1. Values from angular.json
  2. CLI Options
  3. Values from formbar.config.json

In other words: Values from formbar.config.json overwrite values from the CLI Options, which overwrite values from the angular.json.