Managing animations with multiple components in Angular 2+

I am currently developing an Angular application that will utilize a series of Modals in a wizard-style setup.

For this project, I am utilizing the Angular-cli tool.

Below is the code snippet showing how I have set up my animations:

  animations:[
    trigger('right-center-left',[
      state('right', style({
          transform: 'translateX(100%)'
      })),
      state('center', style({
        transform: 'translateX(0)',
      })),
      state('left', style({
        transform: 'translateX(-100%)',
      })),
      transition('right => center', animate('300ms ease-in')),
      transition('center => left', animate('300ms ease-in')),
    ]),
  ],

The application includes five divs with the class .modal, which will be transitioning. There are buttons linked to functions nextModal() and prevModal(). The goal is for the current modal to slide out when nextModal() is called, and the next one to slide in, with the reverse action for prevModal().

To illustrate, here is an example of how these functions are implemented within the template:

<button class='right-btn' (click)='prevModal(addressModal,phonesModal)'>Previous</button>
<button class='left-btn' (click)='nextModal(phonesModal, emailModal)'>Next Part</button>

Additionally, the following functions handle the transition between modals:

  nextModal = (current, next) => {
    current = 'left';
    next = 'center';
  }
  
  prevModal = (prev, current) => {
    prev = 'center';
    current = 'right';
  }

Answer №1

Utilizing a template decorator on an element

<li *ngFor="let hero of heroes"
    [@right-center-left]="hero.state"
    (click)="hero.toggleState()">
  {{hero.name}}
</li>

p.s. There may be an error with the name, consider changing it to RightCenterLeft or another animation name, such as SlideAnimation.

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

Strategies for preventing multi-level inheritance of TypeScript class properties and methods

In my current JavaScript class structure, the DataService is defined as follows: // data.service.ts export class DataService { public url = environment.url; constructor( private uri: string, private httpClient: HttpClient, ) { } ...

Capture data from a Telegram bot and store it in a Google Sheet

I am trying to use a spreadsheet through a Telegram bot as a TODO list so that when I input something on my phone, it is saved in the spreadsheet. (I'm following this tutorial https://www.youtube.com/watch?v=XoTpdxbkGGk, which seems accurate with Goog ...

Navigating with header tags and using the navbar in react-router

Here is the code snippet I am working with App.tsx import React, { FC, Fragment } from "react"; import Nav from "./Components/Nav/Nav"; const App: FC = () => ( <Fragment> <Nav /> </Fragment> ); export default App; Nav.tsx ...

Error: The NgTools_InternalApi_NG_2 member is not exported in compiler-cli/src/ngtools_api

Currently, my ng serve command is not working and showing the following error message: ERROR in node_modules/@angular/compiler-cli/index.d.ts(20,10): error TS2305: Module '"./node_modules/@angular/compiler-cli/src/ngtools_api"' has no expor ...

Angular 14 is experiencing issues with NgRx Store failing to properly recognize the payload

The issue lies in TypeScript not recognizing action.payload.index as a valid property. I am unsure how to resolve this problem and make the 'index' visible in my project. shopping-list.actions.ts import {Action} from "@ngrx/store"; im ...

The functionality of the Ionic 4 app differs from that of an Electron app

I've encountered an issue with my Ionic 4 capacitor app. While it functions properly on Android studio, I'm having trouble getting it to work on Electron. Any ideas on how to resolve this? Here are the steps I took to convert it to Electron: np ...

React Native Expo Launch disregards typescript errors

While using Expo with Typescript, I've noticed that when I run the app with expo start or potentially build it, TypeScript errors are being ignored. Although Visual Studio Code still flags these errors, I can still reload the App and run it on my pho ...

Attempting to simulate the behavior of Angular2 Token during testing

Currently, I am working on obtaining a token that is required for API authentication to retrieve a list. My approach begins with importing the angular2-token library: import { Angular2TokenService } from 'angular2-token'; After this, I include ...

Typescript error: The value "X" cannot be assigned to this type, as the properties of "Y" are not compatible

Disclaimer: I am relatively new to Angular2 and typescript, so please bear with me for any errors. The Challenge: My current task involves subtracting a start date/time from an end date/time, using the result in a formula for my calculation displayed as " ...

angular2 angular-entity directive

I have developed a component that accepts a template: export class TemplateParamComponent implements OnInit { @Input() items: Array<any>; @Input() template: TemplateRef<any>; } Here is the HTML code: <template #defaultTemplate le ...

Tips for adjusting card content to fit its size in material ui?

I'm looking to implement Material UI cards in a grid layout, each containing a Highcharts chart as shown in this demo. However, I'm facing an issue where the content does not adjust properly when the card size is fixed. How can I resolve this? A ...

Transition color seamlessly from the left side to the right side upon hover

Here is a simple code snippet for creating a line that changes color on hover: li::after { height: 2px; display: block; background: rgb(195, 195, 195); border-right: 1px white; content: ''; } li:hover:after { position: relative; ...

Styling the `mat-hint` in Angular Material for large blocks of text

Currently, I am undertaking a project in Angular 9 and utilizing Material design. If you want to view a demo of my work, you can find it here: https://stackblitz.com/edit/mat-hint-styling-issue?file=src/app/app.component.html In my project, I am using in ...

Can you tell me the data type of IconButtons in Material UI when using TypeScript?

Currently, I am in the process of creating a sidebar using Material UI in Next JS with typescript. My plan is to create a helper function that will help display items within the sidebar. // LeftSidebar.tsx import {List,ListItem,ListItemButton,ListItemIcon ...

The correlation between methods in programming languages

Can a class or object be created with type constraints between methods? abstract class Example<T>{ abstract methodOne(): T abstract methodTwo (arg: T):any } I am looking to ensure that the argument of methodTwo is the same type as the return ty ...

"Exploring the world of asynchronous calls in Angular2

I'm encountering a common HTTP race condition, but I lack sufficient knowledge of Angular2 and Observables to troubleshoot my issue. Let me explain the setup: [ FormComponent ] | | 1| |6 | | [ MetadataService ...

Utilizing the [mat-dialog-close] directive within an Angular dialog component

While attempting to utilize the suggested code in the dialog template for opening a dialog component to either confirm or cancel an action, I encountered an error with the following message. Why did this happen? Property mat-dialog-close is not provided by ...

gulp-webpack is unable to locate node packages

Currently working on developing a modern Angular application. I have opted to use gulp-webpack for quick development builds. To handle my TypeScript bundling and node modules dependencies, I am relying on webpack. However, it seems that gulp-webpack is no ...

The ngTemplateOutletContext context source is not defined

That snippet of code was functional with Angular 2, and possibly even with versions earlier than Angular 4.3.6. Currently, the gradingKey object is undefined within the display or edit template section. However, it is not undefined in the getTemplate(gra ...

Steps to create a formGroup in Angular 12

import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; @Component({ selector: 'app-signup', templateUrl: './signup.component.html', ...