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

93
Views
Angular show hide with combine condition

I have an array of object need to show hide based on filter like below:

HTML CODE:
    Filter:
        <div (click)="filter(1)"> F1 </div> 
        <div (click)="filter(2)"> F2 </div> 
        <div (click)="filter(3)"> F3 </div> 
        <div (click)="filter(4)"> F4 </div> 
    
      <div *ngFor="let data of datas">
            <span *ngIf="data.show">
            {{data.name}}
            </span>
        </div>

ts Code:
 this.datas = `[{'name':'product one','filter':'1'},{'name':'product two','filter':'2'},{'name':'product three','filter':'3'},{'name':'product three','filter':'3'},{'name':'product','filter':''},{'name':'product','filter':''},{'name':'product one','filter':'1'},{'name':'product'}]`

filter(query){
    this.datas.forEach(function (element, index) {
        if (element.filter == query ) {
            element.show = true;
        } else {
            element.show = false;
    }

I have tried the above approach it's not working . Expected like:

  1. By default display all product.
  2. Filter is toggle(on/off)
  3. Need to filter like (F1 & F2 & F3) at the same time like combination
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Observation/Suggestions :

  • Instead of adding a new property show. You can easily achieve that by filtering out the datas array based on the value passed in the filter() method.
  • Instead of modifying the original array, you can make a deep copy and do the operation on click on filter().

Working Demo : https://jsfiddle.net/srvpw2bo/

about 4 years ago · Juan Pablo Isaza Report

0

The array objects do not have the show property that you test in the *ngIf directive

about 4 years ago · Juan Pablo Isaza Report

0

Rather simple, really.

I made you a small stackblitz app. But you also really, really need to work on your code. Even as a description for your help, this is just pretty messy.

I didn't code your "Multiple Selections" for you.

https://stackblitz.com/edit/angular-ivy-fbpgdv?file=src/app/app.component.ts

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!