Reputation: 27
I want to blur the span element having test "Blur me" whenever I click on checkbox
html file
<input (click)="clickbox()" type="checkbox">
<span>
<span class="blur"> Blur Me </span>
<input [disabled]="ischecked" type="month">
</span>
TS file
ischecked = true;
clickbox() {
console.log(this.ischecked);
this.ischecked = !this.ischecked;
}
Upvotes: 0
Views: 912
Reputation: 458
In your html:
<span [class.blurred]="isChecked">
</span>
And add a class into styles with the following code:
.blurred {
color: darkgrey;
}
Upvotes: 2
Reputation: 24424
you can use ngClass directive to toggle a class like this 👇
<span [ngClass]="{blur:ischecked }" > Blur Me </span>
Upvotes: 0
Reputation: 1212
Try this component.html
<input (click)="clickbox()" type="checkbox">
<span>
<span [ngClass]="(!ischecked) ? '': 'blur'"> Blur Me </span>
<input [disabled]="ischecked" type="month">
</span>
component.css
.blur {
opacity: 0.5;
}
component.ts
clickbox() {
console.log(this.ischecked);
this.ischecked = !this.ischecked;
}
Upvotes: 1
Reputation: 1648
Update this line in code
<span class="blur"> Blur Me </span>
to this
<span [ngClass]="{'blur': ischecked}"> Blur Me </span>
Upvotes: 0