chrisjavieroliveros Posted February 3, 2021 Posted February 3, 2021 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: Thanks! I'm looking forward to be very active in this community!
Solution ZachSaucier Posted February 3, 2021 Solution Posted February 3, 2021 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 }); 3
chrisjavieroliveros Posted February 3, 2021 Author Posted February 3, 2021 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!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now