How can a div be displayed next to another div when it is clicked using angular2?

Is there a way to have another page show up after clicking on a div, like shown in the image below?

Before Click:

After Click:

Answer №1

If you want to display a new component on your webpage, follow these steps:

First, add a button in your HTML template. Then use the proper tags to indicate where you want the new component to appear.

<h1>Billing<a (click)="newBilling()"></a></h1>
<div class="col-xs-6">
     <app-billing-list *ngFor="let billingEl of billings; let i = index" 
     [billing]="billingEl" [index]="i">
     </app-billing-list>
</div>
<router-outlet></router-outlet>

In your Component's TypeScript file, create a new function (for example, newBilling()) that will handle data manipulation and redirecting to another URL. For instance, you can go from http://localhost:3000/billing to http://localhost:3000/billing/new.

newBilling() {
    this.router.navigate(['new'], { relativeTo: this.route });
}

Next, update your routing module by adding a path for the new component. In this case, 'new' is a child route of 'billing', and accessing billing/new will load the BillingEditComponent.

const appRoutes: Routes = [
path: 'billing', component: BillingComponent, children: [
    { path: 'new', component: BillingEditComponent },

I hope this explanation is helpful to you.

Answer №2

To complete this task, there are two key actions to take:

Displaying and Concealing Divs

The primary aspect of the question is fairly straightforward. Utilize ngif for this purpose: https://angular.io/api/common/NgIf

Structuring CSS

The layout will vary based on the existing CSS setup. Consider exploring CSS Flexbox or conducting a search for dual-column layouts.

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

Dealing with problems related to types in React and TypeScript createContext

Struggling to pass the todos (initial state) and addNewTodo (methods) using React Context hook and typescript. Despite trying multiple solutions, errors persist. Partial generics do not cause issues in the context component, but I encounter the error Cann ...

Modifying the color of a variety of distinct data points

There was a previous inquiry regarding Changing Colour of Specific Data, which can be found here: Changing colour of specific data Building upon that question, I now have a new query. After successfully changing the 2017 dates to pink, I am seeking a way ...

Tips for running a Nativescript-Angular app in the background

I am currently developing a hybrid app using NativeScript and Angular that has the capability to send real-time location updates from the user to a server via the geolocation plugin, among other features. While everything seems to be working fine when the ...

Executing a series of HTTP requests sequentially using Angular 5

I need some guidance on sending an array of HTTP requests in sequential order within my application. Here are the details: Application Entities : Location - an entity with attributes: FanZone fanZone, and List<LocationAdministrator> locationAdmins ...

Is it possible to alter the background color once the content of an input field has been modified?

I am working with an angular reactive form and I want to dynamically change the background color of all input fields when their value is changed. Some of these input fields are pre-populated and not required. I came across a potential solution on Stack Ove ...

Switching over to Typescript: Sending mapped properties

I'm having trouble converting my React.JS script to TypeScript. I need assistance in creating a drop-down navigation bar on my website. Here's a snippet from my Header.tsx file: The error message Property 'onClick' does not exist on t ...

Setting default parameters for TypeScript generics

Let's say I define a function like this: const myFunc = <T, > (data: T) => { return data?.map((d) => ({name: d.name}) } The TypeScript compiler throws an error saying: Property 'name' does not exist on type 'T', whic ...

Issues arise after upgrading Node and npm, causing an inability to execute any npm command

Following an upgrade to the latest Node and npm version, I encounter an error when attempting any npm command: C:\Users\...>npm doctor TypeError: Cannot read property 'prefix' of undefined at parseField (C:\Users&bs ...

Leverage the state from a Context within a Class-based component

I have a Codepen showcasing my current issue. I want to utilize the class component so that I can invoke the forward function from parentComponents via ref. However, I am struggling with how to manipulate the context where the application's current st ...

Angular 6 - Ensuring all child components are instances of the same component

My issue has been simplified: <div *ngIf="layout1" class="layout1"> <div class="sidebar-layout1"> some items </div> <child-component [something]="sth"></child-component> </div> <div *ngIf="!layout1" class= ...

Having to reinstall node modules is a repetitive task that must be done after each build of an Angular

Formulating this question has been quite challenging for me. I really hope it is clear. Despite my extensive searches, both on this platform and beyond, I have not been able to find any reference to the behavior I am experiencing. For the past few ...

Guide to navigating to a specific route based on location in a Node.js Express application

Currently, I am integrating the official i18n library to localize my Angular Universal application and utilizing a proxy to deliver the localized versions. The app is functioning properly when there is a language specified in the URL (e.g: /en/page), but e ...

An unexpected error has occurred: Uncaught promise rejection with the following message: Assertion error detected - The type provided is not a ComponentType and does not contain the 'ɵcmp' property

I encountered an issue in my Angular app where a link was directing to an external URL. When clicking on that link, I received the following error message in the console: ERROR Error: Uncaught (in promise): Error: ASSERTION ERROR: Type passed in is not Co ...

There is no index signature containing a parameter of type 'string' within the type '{ appointments: { label: string; id: number; minWidth: number; }[]; }'

Just getting started with React and Typescript. I'm attempting to extract data from the configuration file based on the input(props), but it seems like Typescript is throwing errors. Any suggestions on how to tackle this issue? config.json { "t ...

Angular is notifying that an unused expression was found where it was expecting an assignment or function call

Currently, I am working on creating a registration form in Angular. My goal is to verify if the User's username exists and then assign that value to the object if it is not null. loadData(data: User) { data.username && (this.registrationD ...

The issue arises when attempting to invoke a method from a global mixin in a Vue3 TypeScript component

I've been working on this challenge for the past week, and I would appreciate any help or insights from those who may have experience in this area. Currently, I am in the process of converting vue2-based code to vue3 for a new project. Instead of usi ...

Creating a custom Angular 5 package integrated with external JavaScript libraries

I have developed a custom wrapper for a JavaScript library and I want to distribute it via npm. For this purpose, I am utilizing SystemJS and scriptloader to load the JavaScript library. The setup is working correctly and I am able to successfully build ...

Ways to determine the current active tab in React are:

Currently, I am facing an issue with my code involving two tabs. Upon clicking on the second tab, I want to display a specific message. However, I am struggling to determine when the second tab is selected. The main problem lies in the fact that the selec ...

Ways to eliminate the dynamically included angular files from the .net core web api project

Embarking on a new project, I aim to utilize asp.net core web.api and angular 9. My initial goal is to establish a .net core web api project without MVC or scaffolded angular project. What I desire is to have the spa launch along with the web.api, mirrorin ...

Discovering the type in Typescript by specifying a function parameter to an Interface

Consider this sample interface: interface MyInterface { x: AnotherThing; y: AnotherThingElse; } Suppose we make the following call: const obj: MyInterface = { x: {...}, y: {...}, } const fetchValue = (property: keyof MyInterface) => { ...