0

I have the following jQuery code that is used for adding some animations to a Signup form when clicking on the submit button.

        setTimeout(() => {
            $('#new-user-layout').addClass('animate__fadeOut')
        }, 1000)
        setTimeout(() => {
            $('#new-user-layout').addClass('hidden')
        }, 1300)
        setTimeout(() => {
            $('#new-user-layout').removeClass('animate__fadeOut')
            $('.app-login_form-layout').css({ 'height': '28rem', 'width': '25rem' })
        }, 1600)
        setTimeout(() => {
            $('#user_credentials').removeClass('hidden')
            $('#user_credentials').addClass('animate__fadeIn')
        }, 2000)
        setTimeout(() => {
            $('#user_credentials').removeClass('animate__fadeIn')
        }, 2300)

Now this is with the HTML template that I need to convert to Angular code. How can I add these animation classes in Angular way ?

I tried using [ngClass], but it is not working properly.

1 Answer 1

1

You can use ViewChild, ElementRef and Renderer2 as below

@ViewChild("newuserlayout") newuserlayout: ElementRef;

  constructor(private renderer: Renderer2) {}

  ngOnInit() {
    setTimeout(() => {
      debugger;
      this.renderer.addClass(
        this.newuserlayout.nativeElement,
        "animate__fadeOut"
      );
    }, 1000);
  }

Demo https://stackblitz.com/edit/angular-viewchild-elementref-render2

Sign up to request clarification or add additional context in comments.

4 Comments

Elegant. You are awesome !!! Thanks a lot. This is the perfect solution.
Meh.. why not use Angular animations for this?
@MikeOne how that can be used ?
Maybe this helps? angular.io/guide/animations

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.