I am seeking to verify if a user has chosen an item from the ngFor form and then redirect them to another page upon submitting the form with the updated value.
HTML:
<mat-select placeholder="Treatment" [(ngModel)]="model.TreatmentA" name="TreatmentA" #TreatmentA (change)="onChange(TreatmentA.value)"
disableRipple>
<mat-option value="Sutent (Sunitinibum) 25mg">Sutent (Sunitinibum) 25mg</mat-option>
<mat-option value="Sutent (Sunitinibum) 37.5mg">Sutent (Sunitinibum) 37.5mg</mat-option>
<mat-option value="Sutent (Sunitinibum) 50mg">Sutent (Sunitinibum) 50mg</mat-option>
</mat-select>
<div class="row">
<button mat-raised-button color="primary" type="submit" value="submit">Update Patient</button>
<button mat-raised-button color="accent" (click)="goBack()">Cancel</button>
</div>
TS
private onChange(TreatmentAValue): any {
console.log(TreatmentAValue);
}
onChangeSubmit(){
const CONDITION = true;
const DATA = this.onChange(this.TreatmentAValue);
const ERROR = new Error(this.goBack())
const promise =
new Promise((resolve, reject) => {
// do some async stuff
this.router.navigate(['/patient/ra', this.id]);
if (CONDITION) resolve(DATA);
else reject(ERROR);
})
updatePatient() {
this.patientService
.updatePatient(this.model)
.subscribe(() => this.onChangeSubmit());
}
model = new Patient();
id = this.route.snapshot.params['id'];
private getSinglePatient(): any {
this.patientService
.getPatient(this.id)
.subscribe(patient => {
this.model = patient[0];
})
}
}
In summary, I need to confirm if a selected treatment value has changed for a specific field, and then direct the user to the desired component only if they have selected a new treatment from the list when submitting the form...