Jump to content
Search Community

Angular 11 + GSAP: Invalid property; Missing Plugin?

chrisjavieroliveros test
Moderator Tag

Go to solution Solved by ZachSaucier,

Recommended Posts

Hello! I just started learning GSAP today and I'm trying to use this with Angular 11. A while back (Angular 7?) it was very easy to import and use GSAP with Angular. Now it doesn't seem so. (I most probably just missed something.)


What's wrong with my code?

import { Component, ViewChild } from '@angular/core';
import { gsap } from 'gsap';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  constructor() {}

  @ViewChild('box') box?: any;

  ngAfterViewInit() {
    gsap.to(this.box, { x: 100 });
  }
}

It's returning this error:
1739262134_ScreenShot2021-02-03at5_16_56PM.png.3e7eba7d32f51b369ccef12bf59f5d40.png

 

 

Thanks! I'm looking forward to be very active in this community!

 

 

Link to comment
Share on other sites

  • Solution

Hey chrisjavieroliveros and welcome to the GreenSock forums.

 

That warning usually means that the target that you're animating isn't a DOM element and doesn't have an x property. Most likely this.box is some state object and not the DOM element itself. I've never used Angular 11, but based on this article, it looks like you should use this.box.nativeElement instead:

gsap.to(this.box.nativeElement, { x: 100 });

 

  • Like 3
Link to comment
Share on other sites

1 hour ago, ZachSaucier said:

Hey chrisjavieroliveros and welcome to the GreenSock forums.

 

That warning usually means that the target that you're animating isn't a DOM element and doesn't have an x property. Most likely this.box is some state object and not the DOM element itself. I've never used Angular 11, but based on this article, it looks like you should use this.box.nativeElement instead:


gsap.to(this.box.nativeElement, { x: 100 });

 

Ah! I remember now! Thank you Zach! 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...