Add class to an element in Angular 4

前端 未结 5 1948
北荒
北荒 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:56

    Use [ngClass] and conditionally apply class based on the id.

    In your HTML file:

  • In your TypeScript file:

    addClass(id: any) {
        this.id = id;
    }
    

提交回复
热议问题