Tips for displaying a form after clicking with a delay in Angular 7

I need to update some AngularJS code for Angular 7.

There is a function that displays a new form below the main one when clicked.

HTML

<img [hidden]="!skillsToDelete" (click)="showFormDelete(skill)" title="Delete" class="cross" src="../../../assets/icon/deletex.png">

TypeScript

this.showCompDelete = false;

showFormDelete(skill) {
    this.showCompDelete = !this.showCompDelete;
    this.skillsToDelete.push(skill);
}

HTML DELETE COMPONENT

<div class="col-md-12 col-sm-12 newForm" id="deleteSkill" *ngIf="showCompDelete">

CSS

.newForm{
    padding-left: 0;
    height: auto;
    opacity: 1;
    transition: height ease 0.3s, opacity ease 0.3s, margin-bottom ease 0.3s, padding-top ease 0.3s
}

The transition effect is not working, even after trying -webkit extension.

This is how it used to be:

HTML

<div class="col-md-12 col-sm-12 newForm" id="deleteSkill" style="display: block;">

JavaScript

$scope.showDeleteForm = function () {
        $('#formSkill').hide(300);
        $('#formExp').hide(300);
        $('#initSkills').hide(300);
        $('#certifiedSkill').hide(300);

        if($scope.skillToDelete.length){
            $('#deleteSkill').show(300);
            setTimeout(function () {
                $('.yesno').show(200);
            }, 300);
        }
        else{
            $('#deleteSkill').hide(300);
            $('.yesno').hide(0);
        }

    };

I want to avoid using CSS and instead incorporate a show(300) method in TypeScript. However, any suggestions involving CSS are also welcome.

Answer №1

Instead of using CSS, you can utilize angular-animation

Check out the functional example code here

Import animation in your TypeScript file and implement it as shown below:

In animate('1000ms 3000ms', specify the duration of the animation (1 second in this case) and the delay time (3 seconds in this case)

import { Component } from '@angular/core';
import sdk from '@stackblitz/sdk';
import { animate, state, style, transition, trigger } from '@angular/animations';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ],
  animations: [
        trigger('showAnimation', [
            transition(':enter', [
                style({opacity: 0}),
                animate('1000ms 3000ms', style({opacity: 1}))
            ]),
            transition(':leave', [
                state('invisible', style({opacity: 0})),
                style({opacity: 1}),
                animate('1000ms 3000ms', style({opacity: 0}))
            ])
        ])
    ],
})
export class AppComponent  {
skillsToDelete=false;
showCompDelete=false;
animationState="leave";

showFormDelete(skill) {
    this.showCompDelete = !this.showCompDelete;
    this.animationState=this.animationState=="enter"?'leave':'enter';
    // this.skillsToDelete.push(skill);
}
}

In your HTML file, make use of *ngIf with the following code:

<img *ngIf=  "!skillsToDelete"
 (click)="showFormDelete(skill)" title="Delete"
 class="cross"
 src="https://i.sstatic.net/B4Ha4.jpg">

 <div class="col-md-12 col-sm-12 newForm" id="deleteSkill" *ngIf="showCompDelete" [@showAnimation]="animationState"> 
 form with animation
 </div>

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

Choose Angular Material to dynamically display the state of multiple items as either checked or unchecked

Currently, I am utilizing <mat-select> from Angular Material for multiple choice selection. Is there a particular property that can be set for <mat-option> to determine whether an option should be checked or unchecked based on a parameter? For ...

The offline functionality of the Angular Progressive Web App(PWA) is experiencing difficulties

As per the official guidelines, I attempted to create a PWA that functions in offline mode using pure PWA without angular-cli. However, despite following the official instructions, I was unable to make it work offline. The document in question can be foun ...

Jquery for controlling the navigation menu

I'm new to JavaScript and facing 3 challenges: 1. When I click on the parent <li>, the correct content of the child <sub> does not show up. Each category like "colors, shapes, sizes" should have corresponding child categories like "green, ...

Interactive sidebar component with navigation and animated section markers

For weeks, I've been attempting to create a navigation sidebar similar to the ones shown in these images: Even though getbootstrap.com/components offers appealing navigation sidebars, I have not found a built-in component in their library. This has m ...

Guide to transferring a Django text field to an HTML attribute and accessing it with JavaScript

Looking to transfer a caption from a Django template to JavaScript for an image? Below is the relevant portion of the HTML code: <ul id="portfolio"> {% for picture in gallery_selected.photo_set.all %} <li><img src={{ picture.path }} a ...

Guidelines on launching an ionic 4 modal using routes

How can I open a modal using routes? I attempted the following approach, but it did not work as expected: ngOnInit() { this.launchModal(); } async launchModal() { const modal = await this.modalController.create({ component: AuthPasswordR ...

Anchoring links on a webpage that provide users with a clear indication of their current position within the page

In the scenario of a single-page website with various sections (divs) and a header containing links to different anchors on the page, there is a desire to have an indicator highlight which anchor the user is currently viewing. An example of this can be s ...

Category-Specific Page Display

Can anyone help with CSS coding using Wordpress Elementor to make a page only display posts from the coaching category? I attempted to use this selector article.type-post:not(.category-coaching) { display: none; }, but it doesn't seem to be functi ...

Separate the data into categories and create pie charts to represent each one

I am currently retrieving data from a backend database server, and the information being returned is as follows: [{ "Year": 2014, "Name": "A", "Values": 18 },{ "Year": 2014, "Name": "B", "Values": 16 },{ "Year": 2015, "Name": "D", "Values": 20},{ "Year": ...

Retrieving Dropdown Value in Bootstrap 5: How to Obtain the Selected Item's Value from the Dropdown Button

I am having a slight issue with my dropdown button where I am trying to display the selected item as the value of the dropdown button. The Flag Icon and Text should be changing dynamically. I have tried some examples but it seems that it is not working as ...

In what ways can the content of <tr> be switched?

Hey there! I've written a cool little script for toggling the content of a table. The content is hidden inside a <div> with the class "hiddenDiv". In order to reveal it, there is a <span> with the class "toggle" that contains a link. Click ...

Retrieve properly formatted text from the editor.document using the VSCode API

I have been working on creating a personalized VSCode extension that can export the current selected file contents as a PDF. Although PrintCode exists, it does not fit my specific needs. The snippet of code I am currently using is: const editor = vscode.w ...

Generating a multiplication grid using PHP

I'm currently facing a challenge regarding the presence of an additional "0" box on my multiplication table. Below is the code that I have been working with: $cols = 10; $rows = 10; $number = 0; $number2 = 0; echo "<table border=\"1\"> ...

After unsubscribing from RxJS timer, it starts again

Trying out a simple reflex-testing game here. The player has to click on the red rectangle when it turns green, and their score is displayed. However, the issue is that the timer restarts after clicking on the rectangle even though I tried using 'unsu ...

How to detach functions in JavaScript while preserving their context?

Can functions in JavaScript be detached while still retaining access to their context? For instance, let's say we have an instance of ViewportScroller called vc. We can retrieve the current scroll position with the following method: vc.getScrollPosi ...

Adjusting the slider with jQuery and CSS to extend beyond 100% while remaining within the div boundaries

Currently, I'm working on customizing a jQuery slider. My goal is to achieve the same functionality as the jQuery UI slider where you can set a max value like "2500" and the slider will smoothly adjust without going outside of the specified div or scr ...

jQuery function failing to produce the intended results

I am trying to apply the active class to the last img element using HTML and jQuery Below is my code in HTML and jQuery: function initialSteps() { $(".row").find("column:last").find("img:first").className += " active"; // this does not work either ...

CSS Dropping Down Menu Design

Hello everyone! I am taking my first step into web development and currently in the process of revamping my DJ website. Check out my updated site here: I am working on creating a dropdown div within the top-left menu that will display information about t ...

What is the best way to validate a value with the help of the $.post functions in JavaScript?

An example of a script: <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script> <script type="text/javascript"> $(document).ready( function() { function validateInput( value ) { ...

Flexible design for both columns and rows

Currently utilizing Bootstrap 4, I am attempting to achieve the layout depicted in the image below: https://i.sstatic.net/P1g0t.png My current outcome looks like this: https://i.sstatic.net/AHPDl.png This issue arises on screens with a width exceeding ...