To determine if you can enable or not, you can utilize the change event as shown below:
TS file:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
disabledAgreement: boolean = true;
changeCheck(event){
this.disabledAgreement = !event.checked;
}
}
Template:
<mat-checkbox (change)="changeCheck($event)">I agree to Terms & Conditions</mat-checkbox>
<button [disabled]="disabledAgreement" mat-button class="NxtBtnWrap" type="submit">Submit</button>
For further details, click here
Alternatively, you can use ngModel:
TS file:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
})
export class AppComponent {
checked: boolean = false;
}
Template:
<mat-checkbox [(ngModel)]="checked">I agree to Terms & Conditions</mat-checkbox>
<button [disabled]="!checked" mat-button class="NxtBtnWrap" type="submit">Submit</button>
Don't forget to import the FormsModule module in your app.module.ts to use ngModel:
import { FormsModule } from '@angular/forms';
and add it to the imports array:
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
MatCheckboxModule,
MatButtonModule,
FormsModule,
],
bootstrap: [AppComponent]
})
export class AppModule { }