Angular - getting started
It is easy to set up a new project where your front end uses the Angular framework.
On this page, we shall show you how to set up an empty project that you can use as a blank canvas for adding Angular and Genesis components.
These simple steps create an app you log run and log into, and an empty home page. You are then ready to go into the code and add some components.
We shall also look briefly at:
- the folder structure of the project
- the principles of routing and styling an application
You can find out more by looking into our example application, where you can look at the code and check the results against the running application.
Setting up the Angular project
- Create a new Angular project. The example below creates a project called myApp using Genx with
--framework Angular
:
npx -y @genesislcap/genx@latest init myApp -s blank-app-seed --framework Angular -x
- Navigate to your new project's client directory:
cd ./client
Install the dependencies and run the app
- Run the following command from your project folder:
npm run bootstrap
- Start the app in development mode:
npm run dev
The development server launches your project and makes it available on localhost:
The project is currently based on Angular 18.
Project folder structure and main elements
src/main.ts
This is the main entry point for the application. It bootstraps the app by rendering the app.module.ts module into the DOM. The file also registers PBCs using registerPBCs
src/pbc
This folder contains components that are responsible for enabling the insertion of slots within the application.
These slots act as placeholders where content, provided by the registered Project Building Components (PBCs), is rendered dynamically. The PBCs are registered in the application through main.ts, ensuring that specific components can be inserted into the designated slots at runtime.
src/app/share
The share folder holds shared resources and components that are used across the entire application.
Key files are:
- genesis-components.ts. This registers Genesis framework components, including forms, layouts, and charts.
- foundation-login.ts. This configures the foundation-login micro front-end component that handles authorisation and integrates it with the routing system.
src/app/pages
This folder contains the main pages of the application. Each page represents a different route or view, such as the auth-login.component.ts, which handles authentication-related flows.
src/app/components
This folder contains reusable UI components that are utilized throughout the app. Components in this folder are not tied to specific pages but are used as building blocks across multiple sections of the application.
Routing
In Angular, routing is essential for creating single-page applications with navigation capabilities.
The routing configuration in app/service/route.service.ts manages and provides routes throughout the application. This file defines a RouteService
service that combines routes from the main application and additional routes from PBC (Pluggable Business Components).
The pbcRoutes
are generated dynamically by mapping over the routes provided by the PBC, extracting essential properties, and wrapping them in a PBCContainer
component. These routes are then combined with the main application's routes into a single allRoutes
array.
The RoutesProvider
uses Angular's dependency injection to make these routes available to the rest of the application by providing them through the RoutesService
.
Additionally, the RoutesService
is provided to access the routes within Angular components. This ensures seamless integration and accessibility of both main application routes and PBC routes throughout the application.
Styling the application
Global styles
You can add global styles by modifying the main stylesheet located at src/styles/styles.css. This file contains styles that apply to the entire application.
Styling components or pages
For more granular control, you can add styles specific to a page or component.
For example, if you want to have unique styling for the page that is displayed when a requested page cannot be found, create a stylesheet called src/pages/NotFoundPage/NotFoundPage.css with styles that only apply to that page.
Design tokens
Design tokens are declared in the src/styles/design-tokens.json file. They offer an effective way to manage and apply styles in your application in a consistent and maintainable manner.
The design tokens enable you to define and manage values such as colours, fonts, and spacing across the whole application. You can modify these tokens to propagate changes wherever they are used in the application.
See more details in our page on Design systems