create a CSS class for the hover state of the button
.hover-text {
color: #fff;
}
Then, inside component, define a variable to store the text for the hover state:
hoverText = "Book Now";
now using ngClass directive to apply the CSS class to the button when it is hovered and change the text to the defined variable
<button
type="submit"class="btn"
*ngFor="let available of availableTime; let i = index"
[ngClass]="{'hover-text': isHovered}"
(mouseover)="isHovered = true"
(mouseout)="isHovered = false"
>
{{ isHovered ? hoverText : available.value}}
</button>
when the mouse is hovered over the button the "hover-text" class will be applied and the text inside the button will change to the value of the "hoverText" variable
2
Answers
An idea might be to use
mouseover
andmouseout
events on the button element.In the HTML template you should do something like:
and in the typescript component:
create a CSS class for the hover state of the button
Then, inside component, define a variable to store the text for the hover state:
now using ngClass directive to apply the CSS class to the button when it is hovered and change the text to the defined variable
when the mouse is hovered over the button the "hover-text" class will be applied and the text inside the button will change to the value of the "hoverText" variable