I want to create a selection dropdown that when the user select a value it will send to the backend controller. This is my code so far anyone could help
HTML
<mat-form-field appearance="fill" >
<mat-select [(ngModel)]="selectedTemplate">
<mat-option *ngFor="let items of filter" [value]="items.value">
{{items.value}}
</mat-option>
</mat-select>
</mat-form-field>
.TS
selectedTemplate(trigger: MatSelectChange){
this.filter = trigger.value;
this.TemplateName = trigger.value;
}
onUpload(){
let formData = new FormData();
formData.set("file",this.file)
formData.set("TemplateName",this.TemplateName)
console.log(this.TemplateName);
this.http.post(this.appsetting.baseURL 'MyFiles/UploadExcelFile',formData)
.subscribe((response)=>{
console.log(response);
Swal.fire({
title:'Uploaded Successfully',
icon: 'success',
heightAuto: false,
width: 400
}).then((result)=>{
if (result.isConfirmed){
this.refreshPage();
}
})
})
}
CodePudding user response:
Within your mat-select tag, add (selectionChange)="onSelectedTemplateChange($event)"
Then in your component, create a method of
onSelectedTemplateChange(template) {
console.log({template});
}
Once you have that working you should be able to change that method to instead pass to your service.