I'm trying to create a div that triggers a click event. When the user clicks on the "click here" label, I want an alert to appear based on two conditions: first, if getListData is true, and second, only if the label is clicked after 5 seconds of getListData being true. However, my current code isn't working as expected. Here's the snippet below:
home.component.html
<div (click)="clickhere()">Click here</div>
home.component.ts
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
getListData: boolean = false;
constructor(private router: Router) { }
ngOnInit() {
}
clickhere(){
this.getListData = true;
console.log(this.getListData);
setTimeout(function(){
if(this.getListData == true){
alert('true');
}
}, 3000);
}
}