Aurelia - Struggling to integrate CssAnimator with a basic message div

Currently, I am utilizing Typescript and referencing an informative blog post by Mikhail Shilkov.

Even though I am implementing Typescript, the blog post revolves around Javascript. This has led me to ponder whether this difference is the root cause of the issue I am encountering (refer to the error below).

At the beginning of my page, there is a div housing the variable "test" which is associated with a button responsible for altering the value of test.

<template>
    <require from="./animateOnChange"></require>

    <div animateonchange.bind="test">
         ${test}
    </div>

    <button click.delegate="testAnimation()" type="button">test Animation</button>
</template>

In the visual representation:

public test: string = "pears";

testAnimation() {
    this.test = "apples";
}

Following the post, I have embraced custom Attributes in my implementation.

The AnimateOnChangeCustomAttribute class where the error seems to arise is presented below.

import { autoinject, customAttribute } from 'aurelia-framework';
import { CssAnimator } from 'aurelia-animator-css';

@customAttribute('animateonchange')
@autoinject
export class AnimateOnChangeCustomAttribute {

    element: any;

    constructor(element, public animator: CssAnimator) {
        this.element = element;
    }

    valueChanged(newValue) {
        console.log("ELEMENT, NEW VALUE: ", this.element, newValue);
        this.animator.addClass(this.element, 'background-animation').then(() => {
            this.animator.removeClass(this.element, 'background-animation');
        });
    }
}

An issue emerges at this particular line:

this.animator.addClass(this.element, 'background-animation').then(() => {

...indicating that it is unable to read the property 'contains' of undefined.

Uncaught (in promise) TypeError: Cannot read property 'contains' of undefined
at aurelia-animator-css.js:373
at new Promise (<anonymous>)
at CssAnimator.addClass (aurelia-animator-css.js:366)
at AnimateOnChangeCustomAttribute.services/messages/animateOnChange.AnimateOnChangeCustomAttribute.valueChanged (animateOnChange.ts:16)
at BehaviorPropertyObserver.selfSubscriber (aurelia-templating.js:3662)
at BehaviorPropertyObserver.call (aurelia-templating.js:3527)
at Controller.bind (aurelia-templating.js:3388)
at View.bind (aurelia-templating.js:1406)
at Controller.bind (aurelia-templating.js:3409)
at View.bind (aurelia-templating.js:1406)

If anyone possesses insights as to why this failure is occurring, please do share your thoughts.

Additional details I have utilized the exact CSS specifications outlined in the aforementioned blog post.

.background-animation-add {
    -webkit-animation: changeBack 0.5s;
    animation: changeBack 0.5s;
}

.background-animation-remove {
    -webkit-animation: fadeIn 0.5s;
    animation: fadeIn 0.5s;
}
@-webkit-keyframes changeBack {
0% { background-color: white; }
50% { background-color: lightgreen; }
100% { background-color: white; }
}
@keyframes changeBack {
0% { background-color: white; }
50% { background-color: lightgreen; }
100% { background-color: white; }

}

I have included this CSS file at the top of the page within the "" tags designated for this specific view model.

<template>
    <require from="../navmenu/navmenu"></require>
    <require from="../../services/messages/messages"></require>
    <require from="./app.css"></require>
    <!--We want the nav bar to span the page-->
    <div class="container-fluid">
        <navmenu router.bind="router"></navmenu>
    </div>
    <div class="container">
        <div className='col-sm-12'>
            <div className='row'>
                <messages></messages>  //HERE IS THE VIEW MODEL.
            </div>
        <!--We want the media to centre so we use just container-->

            <div className='row'>
                <router-view></router-view>
            </div>
        </div>
    </div>
</template>

Answer №1

Consider updating the constructor to:

constructor(private el: Element, public anim: CssAnimator)

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

Tips for patiently anticipating an object to undergo asynchronous modifications?

I have an array containing items, and I need to incorporate the asynchronous value from getProductMinQuantity. The issue I'm facing is that the response with res.status(200)... gets sent before modifying item.order_quantity_minimum. I had assumed us ...

Using default parameters in a versatile function

There is a function called zip with the following signature: function zip<T, U, V>(ts: T[], us: U[], zipper: (t: T, u: U) => V): V[] An attempt is made to assign a default value of (t, u) => [t, u] to the zipper argument: function zip<T, ...

What is the best way to test an oclif CLI tool that interacts with a Rest API

How can I efficiently test the TypeScript code I've written for an Oclif CLI that interacts with a Node.js and Express.js REST API? I'm currently using Mocha/Chai for testing, but I'm struggling with testing the specific command code from my ...

NextJS compilation sometimes results in undefined errors when using Sass styles

My peace lies in the sass code: .link display: inline-table text-align: center align-self: center margin: 5px 15px font-size: 20px color: black text-decoration: none transition: 0.1s ease-in-out .link:hover text-decoration: underline .l ...

Tips for utilizing programmatic object keys as TypeScript type?

Consider the object shown below: const obj = { foo: "bar", hello: "world", } and this function for processing objects: const process = (obj) => { const processedObj = {} for (const key in obj) { processedObj[`--${key}`] ...

Angular 14 captures typed form data as `<any>` instead of the actual data types

On the latest version of Angular (version 14), I'm experiencing issues with strictly typed reactive forms that are not functioning as expected. The form initialization takes place within the ngOnInit using the injected FormBuilder. public form!: For ...

how can I display the JSON description based on the corresponding ID using Ionic 3

I have a JSON file containing: [{ "id": "1", "title": "Abba Father (1)", "description": "Abba Abba Father." }, { "id": "2", "title": "Abba Father, Let me be (2)", "description": "Abba Father, Let me be (2) we are the clay." }, { ...

Retrieve the object attribute name through the request parameter in Express.js and Mongoose

Setting the Scene The issue at hand is my desire to access the attribute of an Object using the variable provided in the request. A GET /modify/:var request is initiated to alter the attribute of a saved document in MongoDB. In order to determine which at ...

Guide: Incorporating TypeScript in Svelte+ page files

I'm finding the svelte-kit documentation confusing. Starting from scratch with an empty project, I am on a mission to learn about Svelte and build a simple application. I want to implement dynamic routes in my project, and for my +page.ts file, I re ...

What is the reason behind the file not found error encountered when running Deno with the command "echo hello"?

Exploring Deno's standard library, I encountered an issue with Deno.run - a function designed to create a new subprocess. Here is the example provided in the documentation: const p = Deno.run({ cmd: ["echo", "hello"], }); When I attempt to run ...

Utilizing Angular for enhanced search functionality by sending multiple query parameters

I'm currently facing an issue with setting up a search functionality for the data obtained from an API. The data is being displayed in an Angular Material table, and I have 8 different inputs that serve as filters. Is there a way to add one or more s ...

Exploring the concept of using a single route with multiple DTOs in NestJS

At the moment, I am utilizing NestJS for creating a restful API. However, I am currently facing an issue with the ValidationPipe. It seems to only be functioning properly within controller methods and not when used in service methods. My goal is to implem ...

Learn how to create a versatile TypeScript function that combines an array parameter and values to form an object

I've created a function that combines an array of keys with an array of values to form an object. Here's how the function looks: function mergeToObject(keys: string[], values: string[]) { const object:? = {} for (let i = 0; i < keys.length ...

Navigating the correct way to filter JSON data using HttpClient in Angular 4

Struggling with transitioning from Http to HttpClient, here's the code in question: constructor(public navCtrl: NavController, public http: HttpClient, private alertCtrl: AlertController) { this.http.get('http://example.com/date.php') .su ...

Angular CLI: Trouble with building in production mode due to errors in "Abstract class" while using Angular 4

Within my app.resolver.service.ts file, I have an Abstract class. During development, everything works fine, but I encounter an error in the PROD build. import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/commo ...

Tips for incorporating a randomly generated number in WGSL!

Looking to implement a fragment shader within a WebGPU application to generate a black and white image noise effect. For more information on white noise, you can refer to White noise (wikipedia). The goal is for each pixel to have a random color value. I& ...

What could be causing the 404 error when trying to make a get-request to fetch a list of all users?

Having trouble retrieving a list of users using my endpoint, as it keeps returning a 404 error. I have set up a model, controller, router, and index file for the user in my application. Below is the User.ts model: import { Schema } from 'mongoose&apo ...

I am looking to conceal the y-axis labels and tooltip within the react chart

I am currently working with react-chart-2. I have a line graph that displays a tooltip when hovered over, but I would like to hide this tooltip feature. Additionally, I want to remove the numbers 0, 0.1, 0.2 up to 1 on the left side (y-axis) of the gra ...

Creating a function that operates according to the input parameter

Imagine a scenario where I am working with the following JS function: function fetchValue(keyName) { return x => x[keyName]; } Is it possible to define fetchValue in such a way that Typescript's type inference automatically determines the outp ...

When comparing TypeScript class functions with regular functions and variables, which one yields better performance?

When it comes to defining functions, is it better to use variables or functions directly? Also, how does this affect tree-shaking? I am dealing with a lot of calculation-intensive helper classes and I am unsure about the optimal approach in terms of memor ...