Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

444
Views
How to create a clickable div in angular 14 as in the gmail webpage with when it is clicked i need to show my array of data that is in my ts component

So I have created an inbox component which is under nested routing of the main page , BEFORE that I'M trying to create a page that looks and works similarly like the Gmail web app.

So I need to create a set of three div boxes which is clickable and when one is clicked I need to show one list of array that I have stored in the ts component. what function code should I write that makes the DIV Clickable & when onclick() I need to show the list in the array....

this is my html code(inbox.component.html)

<div class="mails" *ngFor="let obj of mail;index as i" (click)="showMessage()" style="cursor:pointer">
    <div id="test">
        {{obj.id}}
    </div>
</div>

this is my ts component(inbox.component.ts)

import { Component, OnInit } from '@angular/core';
import { RouterLink } from '@angular/router';
@Component({
  selector: 'app-inbox',
  templateUrl: './inbox.component.html',
  styleUrls: ['./inbox.component.css']
})
export class InboxComponent implements OnInit {
       
mail=[] as any;
constructor() { 
  
    this.mail=[
      {
      id:1,
      subject:'test1',
      sender:'op',
      message:'hello, how are you',
      },
      {
      id:2,
      subject:'test2',
      sender:'ak',
      message:'hi,who are you'
      }
  ]
  }
  
  ngOnInit(): void {}
  
showMessage(){}
  
}

this is a screenshot of my webmail app that shows a inbox component

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's hard to understand fully what you want to achieve but I believe you are looking for *ngIf directive in combination with (click) listener.

https://angular.io/api/common/NgIf

A structural directive that conditionally includes a template based on the value of an expression coerced to Boolean. When the expression evaluates to true, Angular renders the template provided in a then clause, and when false or null, Angular renders the template provided in an optional else clause.

E.g when div is clicked, it turns boolean isShowing true/false which thanks to *ngIf will render the other <div> or not.

Typescript:

isShowing: boolean = true;
<div (click)="isShowing = !isShowing" >click me</div>
<div *ngIf="isShowing"> I am shown if isShowing = true</div>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!