4

I have the following button

  <button class="btn btn-primary btn-sm" type="button" (click)="executeUsecase(usecase.UsecaseId)"><i class="fa fa-play "></i></button>                                             

it shows a play icon.

I want this play icon to spin when I click on this. How can i achieve it?

I am using typescript in angular 4

SmartestVEGA
  • 8,415
  • 26
  • 86
  • 139

2 Answers2

9

You can use CSS only for that, no Angular required :

button:focus i {
  animation: rotate 1s ease-in-out 0s;
}

@keyframes rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

<button class="btn btn-primary btn-sm" type="button"><i class="fa fa-play"></i></button>
4

You can add a flag in your component as follows:

@Component({
  ...
  template: `
    <button class="btn btn-primary btn-sm"
      [ngClass]="{'clicked': isClicked}" type="button"
      (click)="executeUsecase(usecase.UsecaseId)">>
      <i class="fa fa-play"></i>
    </button>
  `
})
export class Component {
  ...
  isClicked: false;

  executeUsecase(id) {
    ...
    this.isClicked = true;
  }
}

css:

.btn {
  transition: all 2s ease-out !important;
}
.clicked {
  transform: rotate(20deg)
}
Alexandre Annic
  • 9,942
  • 5
  • 36
  • 50