Executing a variety of Components within a single parent component

I find myself in a bit of a dilemma. I have created a component called Application.

In addition, I have several other components such as page1, page2, page3. These are all unique components with various validations and fields that users need to complete. My goal is to display these components sequentially within the Application component. For example, when a user applies for a new "loan," they are directed to the /application route where there is a breadcrumb component and various subcomponents like page1, page2, page3, each serving a different purpose such as personal information or financial details.

Now, my question is, what is the most effective way to manage the current page being displayed to the user? Currently, in the HTML code for the Application component, I am using a switch statement to toggle between displaying page1, page2, and page3. I also use an enum to track the current page so that when the user clicks 'continue' on one page, it advances to the next page based on the enum value. However, I am not entirely satisfied with this approach and would appreciate any suggestions for a better solution.

Below is a snippet from my Application HTML code:

<div class="ui-g">
<div class="ui-g-7 ui-md-offset-2">
    <app-application-steps></app-application-steps>
</div>
</div>
<div class="ui-g">
<div class="ui-g-7 ui-md-offset-2" [ngSwitch]="activeStep">
    <div *ngSwitchCase="'getting-started'">
        <app-application-getting-started></app-application-getting-started>
    </div>
    <div *ngSwitchCase="'personal-details'">
        <app-application-personal-details></app-application-personal- 
    details>
    </div>
</div>
</div>

Each page is implemented as its own component due to their varying dependencies, validation requirements, and code complexity, which helps maintain a clean structure.

If you have any advice or tips on how to improve this setup, I would greatly appreciate it.

Thank you!

Answer №1

Utilize the parent component to control the progression of child views, such as pages in your scenario - the parent component can monitor the current step, similar to how steppers operate.

There are various methods to achieve this, one being a series of conditional components

<mypage1 *ngIf=step===1></mypage1>
<mypage2 *ngIf=step===2></mypage2>
<mypage3 *ngIf=step===3></mypage3>

This is just one approach among many possibilities.

Answer №2

Greetings @Andtoniosssss, I want to express my gratitude for your insightful answer that led me to explore the solution using what is known as Child routes. By organizing each page as a child route of the application, it becomes simpler to manage content display by utilizing a router-outlet in the application's HTML.

The implementation of these child routes is outlined below:

{path: 'application', component: ApplicationComponent, canActivate [AuthGuardService], runGuardsAndResolvers: 'always', children: [
     { path: 'getting-started', component: ApplicationGettingStartedComponent },
     { path: 'personal-details', component: ApplicationPersonalDetailsComponent }]

Subsequently, a router-outlet is integrated into the application's HTML template for rendering these routes effectively.

A heartfelt thank you to everyone involved in this journey.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular 4 - Automatically scroll to specific list item based on search query input

While I can achieve this with custom JavaScript, I'm curious if Angular 4 has any built-in features that could help. I have a list of checkboxes that are scrollable and a search input above them. My goal is to enable users to quickly jump to a section ...

Converting unknown types to interface types in Typescript

I need to create a function called asA that will take a parameter of type unknown and convert it into a specific interface type A, or throw an error if the parameter does not match the interface type A. The solution needs to be resilient. If I add a new f ...

Exploring an array of objects to find a specific string similar to the one being

I recently developed a TypeScript code snippet that searches for objects in a list by their name and surname, not strictly equal: list = list.filter( x => (x.surname + ' ' + x.name) .trim() .toLowerCase() .sear ...

Ionic datetime returns default values upon initialization

I'm currently in the process of developing an Ionic-Angular-app. I require a datetime component on a page to set the creation date of an object. I am using formGroup for this purpose, but whenever I choose a different date, it always reverts back to t ...

Strategies for handling timeouts in TypeScript testing

When I attempt to use the calculator method to trigger the email() method, there seems to be an issue with the elements not rendering properly on the page. After waiting for a significant amount of time, a timeout error is thrown. Has anyone encountered th ...

I'm curious as to why I am receiving an empty array as a response when I send a post request to the API

I am experiencing an issue while sending data to an API using a post method. I have structured the data in an object as per the server's requirements, but upon posting the object to the API, I receive a response with a status of 200 and an empty array ...

Re-subscribe to an Observable that has been unsubscribed in RxJS

Utilizing a Service to periodically "ping" my server every 2.5 seconds, I am able to retrieve the response time from the server by using observables. My implementation also involves angular 2 and typescript. Now, I am facing an issue where I want to be a ...

Tips for creating code coverage reports in Bamboo for Angular applications?

Looking to generate code coverage for my project in Bamboo, but the built-in clover plugin doesn't seem to be displaying any information. Has anyone successfully integrated this feature with Angular projects before? Please note that the build is crea ...

Receiving an Async Thunk result in a Promise

I have a situation where I am making an Axios promise call from an asyncThunk in my Redux toolkit. I am able to capture the responses using Redux toolkit, but I am struggling to figure out how to handle the error response in the "Rejected" state of the sli ...

Concerning the issue of components not loading correctly when using Angular with Lazy Loading Routing

Encountering an unusual issue while utilizing lazyload routing in our application! Within AppModule, there is TopModule followed by DashboardModule, all being loaded lazily. When localhost:4200/dashboard is accessed, the loading sequence is AppModule, To ...

ngx-chips paste pattern division for use in Angular

I am currently working on allowing users to paste a list separated by , ; or | using ngx-chips. The solution involves utilizing the pasteSplitPattern option - which can be set as a string or RegExp. For more information, you can visit https://github.com/ ...

Transform a protractor screenshot into a PDF file

I'm currently working on a small Protractor code that captures screenshots, but my goal is to save these screenshots as PDF files. Below you can find the code snippet I have written. await browser.get(url); const img = await browser.takeScreenshot(); ...

Utilizing CORS and Basic Authentication in Embedded Jetty with ConstraintSecurityHandler

I have an embedded Jetty server running on localhost:8008 and another Angular application accessing it on localhost:4200. I was able to implement CORS by adding the CrossOriginFilter to the svrContext where my webservices are located. However, when I set ...

Dealing with ASP.NET Core: Navigating Windows Authentication and Handling OPTIONS Exception (CORS Preflight)

Currently, I am developing a single-page web application with an ASP.NET Core 3 backend and Angular 9 frontend. For testing purposes, I run the backend on Visual Studio, using IIS Express, at http://localhost:59280. The frontend is operated in Visual Studi ...

How can we use Angular Table to automatically shift focus to the next row after we input a value in the last cell of the current row and press the Enter key

When the last cell of the first row is completed, the focus should move to the next row if there are no more cells in the current row. <!-- HTML file--> <tbody> <tr *ngFor="let row of rows;let i=index;" [c ...

Obtain the object literal string with additional decorative strings surrounding it

In my current Typescript code, I have an object literal structured like this: const MyNamesStrings = { a: { b: "hello", c: "bye" } d: { e: "qwerty" } } However, I am looking for a way to wrap these strings with add ...

Adjust the background color of the header as you scroll

Seeking assistance in adjusting the background color of my header upon scrolling. This is my current implementation: header.component.ts export class HeaderComponent { ngOnInit(): void { const header = document.querySelector('.header'); ...

Struggling to configure setupProxy.js with Duende ASP.NET Core BFF in a TypeScript React project - any tips?

I'm facing some challenges with getting the proxying to work for my local development setup of a Duende BFF with ASP.NET Core 6 and a TypeScript version of a create react app. To check out the repository I've been working on, visit: https://gith ...

React Conditional State Setting

I have created a component that dynamically changes its background color based on the rating of a school. According to the specifications, if the school's rating falls between 1 and 3, the background color should be orange. For ratings between 4 and ...

Tips for efficiently passing an array of functions to Object.assign and applying the same argument to each one

Here is an example of my code: return Object.assign({}, generators(config)); When the generators variable is a single function, everything works fine. However, if it's an array of functions (Function[]) I want to execute all of them with the config ...