In search of captivating hover animations for Angular 6

Seeking Angular 6 animation code similar to this (hover scrolling).

I have linked the jsfiddle below. Attempted in Angular 6 but encountering errors like "Cannot read property 'animate' of null," and "Cannot read property 'hover' of null."

http://jsfiddle.net/gaby/xmAvh/

this.nativeElement.querySelector('#hover1').hover(() => {
      this.amount = '+=10';
      this.scroll();
    }, () => {
      this.amount = '';
    });

 this.nativeElement.querySelector('#container').animate({scrollTop: this.amount}, 100, 'linear', () => {
      if (this.amount !== '') {
        this.scroll();
      }
    });

<div id="hover"> HOVER ME </div>

<div id="container">resemblance reflected in some of the bird's names. It was 30 cm (12 in) long and larger and more robust than any other blue pigeon species. It could raise its hackles into a ruff, which it used for display. Its call sounded like "barf barf" and it also made a cooing noise. It fed on fruits, nuts, and molluscs, and was once widespread in the forests of Mauritius. The bird was first mentioned in 
</div>
<div id="hover2"> HOVER ME </div>

Your assistance is greatly appreciated!

Answer №1

It seems like the error is appearing because the elements have not been created yet. To fix this, try placing the code within the ngAfterViewInit() method since it gets called once all the elements are fully created.

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

Troubleshooting the order of Javascript execution in bundled TypeScript applications

I encountered an issue with the execution order of generated JavaScript code during bundling, resulting in an error message when everything is bundled together. An error occurred: [$injector:nomod] Module 'app.demo' is not accessible! This cou ...

When exporting data to Excel, the date is automatically adjusting based on the timezone. Is there a way to prevent this from happening

Whenever I attempt to export data to excel in angular, I encounter an issue with time zones. The date in the database is set in timezone 'x', while I am exporting data from timezone 'y'. As a result, the exported data in Excel displays ...

Is there another option for addressing this issue - A function that does not declare a type of 'void' or 'any' must have a return value?

When using Observable to retrieve data from Http endpoints, I encountered an error message stating that "A function whose declared type is neither 'void' nor 'any' must return a value." The issue arises when I add a return statement in ...

Display ion-item when selected in Ionic 3

Can anyone help me figure out how to display an item when a specific option is selected? I'm struggling to find a solution, so any assistance would be greatly appreciated. Thank you! <ion-item> <ion-label floating>Reward </ ...

Having difficulties generating ngc and tsc AOT ES5 compatible code

I've explored various options before seeking help here. I have an angular2 library that has been AOT compiled using ngc. Currently, I am not using webpack and solely relying on plain npm scripts. Below is the tsconfig file being utilized: { "comp ...

I need help differentiating "namespace" from "static attributes" in TypeScript

Separating namespace from static properties in TypeScript can sometimes be tricky. error: 'ClassA' only refers to a type, but is being used as a namespace here. class ClassA { static ClassB = class { }; } type T = ClassA // ok type T = C ...

What's the best way to provide route access to the same menu for two distinct user roles using AuthGuard within Angular?

I developed an application that includes three different user roles: ROLE_USER, ROLE_MODERATOR, and ROLE_ADMIN as shown below: export enum Role { User = 'ROLE_USER', Moderator = 'ROLE_MODERATOR', Admin = 'ROLE_ADMIN&apo ...

Can the inclusion of a type guard function impact the overall performance of the application?

const typeGuard = (param: any): param is SomeType => { return ( !!param && typeof param === "object" && param.someProperty1 !== null && param.someProperty2 === null ) } If a type guard function similar to the code above is exe ...

The parameter type 'string | null' cannot be assigned to the value function 'ValueFn<SVGPathElement, Datum[], string | number | boolean | null>'

I recently delved into the world of d3 and attempted to create a simple line chart using d3, TypeScript, and react. However, I keep encountering a TypeScript error whenever I try to implement it. Strangely, I can briefly see my chart before it disappears a ...

Displaying a user percentage loader within the <app-root> element in Angular 2

Here is the content of my index.html: <body> <app-root> Loading... </app-root> ... ... I successfully added a pure CSS loader by replacing Loading... with my own loader. Now I want to implement percentage loading from 0% to 100%, but I ...

Troubleshooting: Angular 7 POST request not communicating with PHP server

Currently, my Angular 7 application is utilizing HttpClient to send a POST request to a PHP server. The process involves a reactive form collecting user input and then transferring it to a specific URL using the following code snippets: admin.component.ts ...

Issue with Angular 12.1: Unable to retrieve value using "$event.target.value"

I am just starting to dive into the world of Angular and have been using YouTube tutorials as my guide. However, I have encountered an error in one of the examples provided. Below is the code snippet that is causing me trouble. HTML <input type=" ...

Issue encountered when attempting to run "ng test" in Angular (TypeScript) | Karma/Jasmine reports an AssertionError stating that Compilation cannot be undefined

My development setup includes Angular with TypeScript. Angular version: 15.1.0 Node version: 19.7.0 npm version: 9.5.1 However, I encountered an issue while running ng test: The error message displayed was as follows: ⠙ Generating browser application ...

Conflicting React types found in pnpm monorepo

In the process of converting an inherited monorepo from yarn+lerna to pnpm workspaces, I am encountering some issues. Specifically, there are mismatching React versions causing errors in typescript. It seems that TypeScript is not recognizing the closest @ ...

Deploying an Angular application on Heroku platform

Recently, I followed this helpful guide to deploy my app: Angular CLI Deployment: Host Your Angular 2 App on Heroku However, today when attempting to deploy another app, the build was successful but the ng build did not run or execute as expected. D ...

Make an indirect mention of a distant JavaScript web address

Our company is looking to incorporate Rollup with Angular 4/Typescript and NPM, and we have a specific set of requirements: Various teams develop JS libraries that need to be centralized, similar to a CDN These libraries are hosted at remote URLs and sho ...

Angular 2 Array Filtering: Mastering the Art

Welcome! I'm a beginner in software development and currently diving into frontend development using Angular 2. My goal is to create a checkbox filter array that will return the selected values upon submission. Below is my code snippet: I've d ...

Separate configurations for Webpack (Client and Server) to run an Express app without serving HTML files

I am currently developing an application with a Node Backend and I am trying to bundle it with Webpack. Initially, I had a single Webpack configuration with target: node. However, I encountered issues compiling Websockets into the frontend bundle unless I ...

Eliminate perfect-scrollbar functionality on mobile devices

I have applied the perfect-scrollbar class with 'height: auto' on mobile screens, expecting it to work properly. It's functioning well in responsive mode on the web. However, it does not scroll on mobile devices. @media (max-width: 992px) { ...

mat-slider: experiencing delay in updating while dragging it

Incorporating @angular/material in my Angular 5 application has been quite the journey. The specific version of Angular Material that I have implemented is 5.0.2, along with @angular/animations 5.1.2. My usage of the slider component is rather straightfor ...