2

I have two link which is displaying two different images on click of respective link.first behaviour is fine but when again I click on selected link, image is displaying correct but hover is moving to another link. I mean its displaying second link as selected. here is what I did up to now.

Can someone help what I am doing wrong?

this.toogleClick is true

loadingImg(folder) {
    this.toggleClick = !this.toggleClick;
    this.meta
      .getToken(
        "images",
        this.imgName.ReportJobId,
        (folder == "input" ?
          this.imgName.UniquePhotoName :
          this.imgName.UniquePhotoName
            .replace(".JPG", ".png")
            .replace(".jpg", ".png")),
        folder
      )
      .subscribe(data => {
        this.imgSrc = this.someurl(data);
      }, () => {
        this.imgSrc = "assets/images/image.jpg";
      });
  }

<ul class="result__image--tabslist">
            <li class="result__image--tab left left__tab" (click)="loadImg('output')">
                <span class="result__tab--txt" [ngClass]="toggleClick?'selected':''">
                    Scan
                </span>
            </li>
            <li class="result__image--tab left" (click)="loadImg('input')">
                <span class="result__tab--txt" [ngClass]="toggleClick?'':'selected'">
                    Original
                </span>
            </li>
</ul>

Quentin
  • 1,865
  • 2
  • 24
  • 40
DharamChauhan
  • 109
  • 1
  • 1
  • 11

2 Answers2

1

You can try with

[class.selected]="toggleClick"

instead of

[ngClass]="toggleClick?'':'selected'"

This way the selected class is applied only if toggleClick is true.

Cristiano Casciotti
  • 1,016
  • 10
  • 21
1

You can try:

[class]="toggleClick?'selected':''"

or,

[ngClass]="{'selected': toggleClick}"

or,

[class.selected]="toggleClick"
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79