Enhance your Angular animations by incorporating parameters into the template trigger

Currently, I am in the process of creating a profile page, and upon loading the page, I aim to have four unique text boxes move in different directions to their respective starting positions (e.g., bottom position transitions to the left, left turns into top, etc.).

My initial approach was to create individual triggers for each text box. However, this method does not align with best practices. As an alternative solution, I attempted to add parameters to the template trigger, allowing me to specify the left and top positions without creating separate triggers for each element.

Unfortunately, I encountered an error suggesting incorrect syntax usage. Regrettably, there is limited documentation available on this matter. If anyone has insights into the correct syntax or could provide guidance, it would be greatly appreciated as my search for solutions online has been challenging.

Please note: The error seems to be related to the presence of an incorrect comma.

Template parse errors:
Parser Error: Unexpected token , at column 24 in [{params: {left_pos: 50%, top_pos: 95%}}] in ng:///AppModule/FindLocalsComponent.html@43:19 ("ileSection__data">{{ focussedUser?.birthDate | age}}</h3>
              </div>
              <div [ERROR ->][@moveText]="{params: {left_pos: 50%, top_pos: 95%}}" class="header-box header-box--left">

Regarding the template, I experimented with the trigger (@moveText) on the left box:

<div class="profileSection" [ngClass]="{
      'visible': markerClicked,
      'not-visible': !markerClicked}
    ">
            <!--there should be a profile picture displayed here-->
            <!-- Other details that we want to display are conencted to the game, such details are currently unknown as we don't know more about the game-->
            <div class="profileSection__header" *ngIf="markerClicked">
              <img class="profileSection__img" *ngIf="!focussedUser?.profilePicture.uploaded" src="assets/images/blank-profile-picture.png" alt="no profile picture">
              <img class="profileSection__img" *ngIf="focussedUser?.profilePicture.uploaded" [src]="'assets/images/profile-pictures/' + focussedUser?.profilePicture.name" alt="the profile picture">
              <div class="header-box header-box--top">
                <h3 class="profileSection__data">{{ focussedUser?.username }}</h3>
              </div>
              <div class="header-box header-box--right">
                <h3 class="profileSection__data">Slytherin</h3>
              </div>
              <div class="header-box header-box--bottom">
                <h3 class="profileSection__data">{{ focussedUser?.birthDate | age}}</h3>
              </div>
              <div [@moveText]="{params: {left_pos: 50%, top_pos: 95%}}" class="header-box header-box--left">
                <h3 class="profileSection__data">Speciality: Potions</h3>
              </div>
              <button class="btn profileSection__btn profileSection__btn--first">Send PM</button>
              <button class="btn profileSection__btn profileSection__btn--sec">Visit Profile</button>
            </div>

As for the component:

@Component({
    selector: 'find-locals',
    styleUrls: ['[your custom CSS file URL]'],
    templateUrl: '[your HTML template URL]',
    animations: [
      trigger('moveText', [
        state('start', style({
          left: '{{ left_pos }}',
          top: '{{ top_pos }}'
        }), {params: {left_pos: 0, top_pos: 0}}),
        transition(':enter', [animate(2000)])
      ])
]
})

In your SCSS file:

.header-box {
      display: block;
      position: absolute;
      width: 20%;
      word-wrap: break-word;
      text-align: center;

      &--top {
        top: 5%;
        left: 50%;
        transform: translateX(-50%);
      }

      &--right {
        top: 50%;
        right: 5%;
        transform: translateY(-50%);
      }

      &--bottom {
        top: 95%;
        left: 50%;
        transform: translateX(-50%);
      }

      &--left {
        top: 50%;
        left: 5%;
        transform: translateY(-50%);
      }
    }

The animation is intended to occur on the right side of the screen where the text blocks are positioned at the bottom, right, left, and top edges of the container.

Answer №1

Make sure to handle the percentage values as strings.

Update the HTML code like so:

[@moveText]="{arguments: {horizontal_pos: '50%', vertical_pos: '95%'}}"

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

Adding a border in jQuery or Javascript to highlight empty form fields

After making the decision to dive into the world of Javascript, I've been dedicated to perfecting a script that will encase empty elements with a border right before the user submits a form. My ultimate goal is to implement live validation in the form ...

Stay Alert: Angular Observable Continuously Monitored for Promise Updates

I am currently working on an angular application that has a connection with a printer. The printer possesses its own status service that is implemented as a promise, providing the printer's current status as a response. However, I am facing an issue w ...

Mastering the Art of Stacking with FontAwesome

I am working on stacking the Soundcloud icon manually to display it within a square similar to fa-facebook-square. However, my Soundcloud icon is appearing under the square. This is the code I have so far: <div class="row"> <ul style="list-s ...

Guide to integrating the (mqtt) JavaScript library into your Angular 2 TypeScript application

I followed a similar approach as demonstrated in how-to-use-moment-js-library-in-angular-2-typescript-app but encountered the error message error TS2307: Cannot find module 'mqtt'. npm install --save mqtt <s>typings install --save mqtt< ...

To accurately determine the width of a div element, it is essential to include the web browser width in the CSS

Is there a way to calculate the width of a div named incontent in the index.php file, based on the width of the browser screen and other data? I have heard about using JavaScript to get the screen width, but the challenge lies in the fact that the stylin ...

Achieving checkbox values in Typescript: A guide

I need help with capturing the values of checked checkboxes and storing them in a string to use in my API. I want to retrieve the value if a checkbox is unchecked. <div *ngFor="let x of groupesTable"> <input type="checkbox" [(ngModel)] ...

Using Angular 5 animations to add delays to lists

I'm struggling to figure out how to add a rotation animation to a list of images with a delay between each one. Currently, I can only achieve a global rotation effect but not the individual delays that I desire. The list trigger works for the initial ...

Executing a particular end-to-end test case using Angular 2, Karma, and Protractor

Is there a specific command I can use to run an individual e2e test case from my test suite? If that's not possible, is there some workaround for running a specific test suite? I'm currently using Jasmine, Karma, and Protractor. To start my tes ...

I am developing a quiz application using JavaScript, and I am wondering how I can smoothly transition from one question to the

I'm working on developing a quiz application and I'm facing an issue where my quiz is skipping question 2 when moving from one question to the next using the "next" button. I have a total of 3 questions in my quiz and for some reason, it jumps fr ...

How to override the styling of a parent element in CSS

I'm encountering an issue with my website's sidebar. I've set the background color to yellow for elements with the currentPage class. This works fine for the 'Home' tab, but when I try to do the same for a nested tab like 'tag ...

Leverage the power of the General Sibling Selector to easily traverse through deeply nested elements in your

Hi there, I have a query regarding the General Sibling Selector. Let's start by looking at the HTML: <div id="layout-middle"> <div id="Center"> <a class="col Picture1">Title1</a> <a class="col Picture2">Title2< ...

Utilize Angular to transform a JSON string into HTML text featuring organized bullet points

I am currently working on a project using Angular and I need to display some data from a JSON file on a webpage. The issue I am facing is that the message is quite lengthy, and I would like it to be presented in bulleted points. "messageToDisplay" ...

Creating a water vessel design using CSS

Despite going through the JS tutorial, I still struggle with it and need some assistance. I believe using a jsfiddle would be helpful. I am attempting to use JS to create a small box that changes color from green to empty based on the fullness of a "wate ...

Is there a way to apply two distinct styles to a single component on a webpage?

Currently, I am in the process of developing a web application using Node JS, React, and Bootstrap. Within the application, I have implemented a main menu and a secondary menu using tabs. I have successfully defined a style for the main menu, but I am faci ...

What are the possible complications that could arise from implementing this system for designing web pages?

Feeling frustrated with the limitations and compatibility issues of CSS, I decided to create a new approach for structuring webpages. Instead of relying on CSS, I developed a javascript library that reads layout instructions from XML files and uses absolut ...

Show two spans, each underneath the other

I am looking to showcase two span elements, one below the other. Take a look at my HTML code snippet <img class="profile-photo margin-0" data-ng-if="!question.isOpen" ng-src="{{question.profilePicId ? que ...

How to Transition an ImageView to a Different Layout in Android

After looking at multiple libraries like TransitionManager, I couldn't find what I needed. I am trying to animate an ImageView similar to the animation shown in this CodePen demo. My goal is to move the image to a button with the ID "Cart" when the ...

Achieving a pulsating SVG animation that functions properly in Internet Explorer

I have an animated SVG that pulses, and while it works in most browsers, it does not function properly in IE. Is there a way to make this animation work in IE without using an animated GIF as a workaround? Check out the code on CodePen <svg version=" ...

The Bootsrap modal fails to open when triggered by a different button

Why does the login button open a signup modal instead of a login modal, even though they are configured in the same way? I renamed the login button to 'loginModel', but it still doesn't work as expected. However, the sign-up button works cor ...

Is there a way to display personalized messages in the console section when visitors access the developer tools on my website?

During a recent exploration of the dev tools on Reddit.com and Facebook.com, I noticed that both sites had custom messages specifically targeting developers who access the console. Reddit was actively recruiting developers through an ad, while Facebook had ...