New Page
Create a new module
For create new module you can use following command from your root directory.
module-name is a name of your desire module.
ng generate module <module-name>
e.g.
ng generate module employee
Add a component to the feature module
For add new component in module you can use following command from your root
directory. module-name is a name of your desire module &
component-name is a name of your component.
ng generate component <module-name>/<component-name>
e.g.
ng generate component employee/salary;
Steps
We are in the process of adding a new page to the admin section, specifically for managing the 'Account Module' with a focus on salary components.
- To create a new
component named salary using Angular CLI, you can run the following command
ng g c salary
Options Description ngRefers to the Angular CLI command. gStands for "generate" — it tells Angular to create something new. cSpecifies that you are generating a component. salaryThe name of the component you're creating.
-
If you're setting up routing for anaccountsmodule in Angular, you would typically define routes in aaccounts.route.tsfile (or similarly named file depending on your project structure). Below is an example of how to structure the routing configuration for anaccountsmodule that includes the SalaryComponent.
import { Route } from '@angular/router'; import { SalaryComponent } from './salary/salary.component'; import { Page404Component } from 'app/authentication/page404/page404.component'; export const ACCOUNTS_ROUTE: Route[] = [ { path: 'salary', component: SalaryComponent, }, { path: '**', component: Page404Component }, ]; -
To integrate the Accounts module routing into theadmin.routes.tsfile, you would need to include a route that points to the AccountsModule. Assuming you're structuring theadmin.routes.tsfile to include links to different modules, here's an example of how to modifyadmin.routes.tsto include a route for AccountsModule (and indirectly for SalaryComponent as part of Accounts).
{ path: 'accounts', loadChildren: () => import('./accounts/accounts.routes').then((m) => m.ACCOUNTS_ROUTE), }, -
To add a new page (like the Salary page under Accounts) to your sidebar menu, you will need to update the sidebar items configuration. This configuration typically resides in a json file likeassets/data/routes.json, which defines the structure of the sidebar menu.
{ path: '', title: 'Accounts', iconType: 'material-icons-outlined', icon: 'library_books', class: 'menu-toggle', groupTitle: false, badge: '', badgeClass: '', role: ['Admin'], submenu: [ { path: '/admin/accounts/salary', title: 'Salary', iconType: '', icon: '', class: 'ml-menu', groupTitle: false, badge: '', badgeClass: '', role: [''], submenu: [], }, ], },
Thats it!
Now you can access salary page using url
http://localhost:4200/#/admin/accounts/salary
Referral Url
| Type | URL |
|---|---|
| Angular | https://angular.io/guide/lazy-loading-ngmodules |