my sulotion (need to use a Directive)
–html
button.component.html
<button class="btn btn-danger" style="width: 110px" appButton"
></button>
–Typescript
button.directive.ts
@Directive({
selector: '[appButton]'
})
export class ButtonDirective implements OnInit {
constructor(private elRef: ElementRef, private renderer: Renderer2) {
}
ngOnInit() {
}
@HostListener('mousedown') onmousedown(eventData: Event) {
if (this.elRef.nativeElement.style.backgroundColor === 'blue') {
this.renderer.setStyle(this.elRef.nativeElement, 'background-color', 'rgba(200,0,0,0.7)');
} else {
this.renderer.setStyle(this.elRef.nativeElement, 'background-color', 'blue');
}
}
solved How do I make a button stay “Pressed” after clicking