1

I have some list of items in my database which I am retrieving in form of an array.I am displaying these items as selectables on my page. On clicking a particular, I want to retrieve it's value ( I want to know which item was selected).

Here's the HTML Code :

 <p>Year Wise Medical Records</p>

        <div class="list-group "  *ngFor="let year of years | async">
              
            <a routerLink="records"  routerLinkActive="active" >
                <mdb-icon fas icon="table" class="mr-3"></mdb-icon>{{year.key}}</a>
                
        </div>

Here's how I am retrieving from the database:

this.years=af.list('/years/'+this.name).snapshotChanges();
Here's the image of how the list looks before and after selection of an item": Before selection of an item On selecting any item

All the items in the list are being highlighted on selecting any of them. Can someone help me with highlighting only that item which has been selected and print that item value on console through typescript.

2 Answers 2

2

Try like this:

Working Demo

<a routerLink="records" (click)="activeYear = year.key" [class.active]="activeYear == year.key" >
      <mdb-icon fas icon="table" class="mr-3"></mdb-icon>{{year.key}}
</a>
Sign up to request clarification or add additional context in comments.

3 Comments

This worked for me! , how can I print the value on console ? the selected item
(click)="activeYear = year.key;getSelectedyear(year.key)"
Added it in the demo
2

you pass index for item

    <div class="list-group "  *ngFor="let year of years; index as i | async">

        <a routerLink="records"  routerLinkActive="active" >
            <mdb-icon fas icon="table" class="mr-3"></mdb-icon>{{year.key}}</a>

    </div>

pass event index create for item target

    <button (click)="deleteItem(i)">delete</button>

Comments

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.