Adding custom components, pipes, providers, and directives in application-provided shared module
You can add new custom components, services, pipes, and directives to the application-provided shared module as per your needs.
Procedure
- Depending upon what you want to add to the shared module, navigate to the corresponding folder:
SCREEN_EXTENSIONS_HOME/shared/{components or directives or pipes or services}.
Create the folders appropriately, if already not present.
- Copy shared-extension.module.ts from <WORKSPACE>/store-frontend/src/app/shared to <WORKSPACE>/store-frontend/store-extensions-src/app/shared folder.
If shared-extension.module.ts is already present then do not copy the file.
- Use one of the following CLI commands to create the component:
Table 1. CLI commands and purposes CLI command Purpose ng g c <component-name> --project=store-extensions —skip-import Generate a component. Note: To be executed from this location: SCREEN_EXTENSIONS_HOME/shared/componentsng g directive <directive-name> --project=store-extensions —skip-import Generate a directive. Note: To be executed from this location: SCREEN_EXTENSIONS_HOME/shared/directivesng g pipe <pipe-name> --project=store-extensions —skip-import Generate a pipe. Note: To be executed from this location: the SCREEN_EXTENSIONS_HOME/shared/pipesng g s <service-name> --project=store-extensions —skip-import Generate a service. Note: To be executed from this location: SCREEN_EXTENSIONS_HOME/shared/services - Update the newly-created component, directive, or pipe class name in the providers property of
@NgModuledecorator in shared-extension.module.ts.Similarly, if you create a provider or service in the SCREEN_EXTENSIONS_HOME/shared/services folder, service class name must be in the declarations and exports property of
@NgModuledecorator in shared-extension.module.ts.
When you are importing classes in custom components, ignore the import suggestions from store-app-build folder.
You must only import classes either from <WORKSPACE>/store-frontend/src or <WORKSPACE>/store-frontend/store-extensions-src.
Ignore all import suggestions from <WORKSPACE>/store-frontend/store-app-build folder. Having import statements from store-app-build might result in errors.