Add class to an element in Angular 4

前端 未结 5 1971
北荒
北荒 2021-02-01 14:28

I was trying to create an image gallery with Angular 4.The logic behind this is to add a Cascading Style Sheet (CSS) class to the selected image that will show a red border on t

5条回答
  •  广开言路
    2021-02-01 14:58

    Here is a plunker showing how you can use it with the ngClass directive.

    I'm demonstrating with divs instead of imgs though.

    Template:

    TS:

    export class App {
      selectedIndex = -1;
    
      setSelected(id: number) {
        this.selectedIndex = id;
      }
    }
    

提交回复
热议问题