A
A
andrkkk2020-02-16 09:37:58
Angular
andrkkk, 2020-02-16 09:37:58

How to access a specific button?

There are identical blocks of html code, for example:

<div *ngFor="let car of carsArray">
    <div>
        <!--тут какая-либо информация о машине-->
    </div>
    <div>
        <button class="btn more-info-btn" (click)=showMore()>Подробнее</button>
    </div>
    <div *ngIf="needMore" class="additional-info">
        <!--тут доп. информация показывается при нажатии на кнопку-->
    </div>
</div>

The method itself just changes the boolean variable:
showMore(){
    this.needMore = !this.needMore
  }

The problem is that since the components are roughly the same, when you press add. information opens on all cards at once, how to open additional. Old only on the card where I clicked?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Stolyarov, 2020-02-16
@andrkkk

<div *ngFor="let car of carsArray; let showMore">
    <div>
        <!--тут какая-либо информация о машине-->
    </div>
    <div>
        <button class="btn more-info-btn" (click)=showMore = !showMore>Подробнее</button>
    </div>
    <div *ngIf="needMore" class="additional-info">
        <!--тут доп. информация показывается при нажатии на кнопку-->
    </div>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question