问题描述
I have an angular form where I have the submit button enabled default. I have four fields I want to use toastr to show an error message when a particular form field is empty
form.html
'''
<div>
<form [formGroup]="bakeryForm" (ngSubmit)="bakeryCreateForm()">
<table>
<div>
<tr>
<td>
<mat-form-field>
<mat-label>Customer no</mat-label>
<input matInput placeholder="Customer no" formControlName="customer no" autocomplete="off" required>
</mat-form-field>
</td>
<td>
<mat-form-field>
<mat-label>customer name</mat-label>
<input matInput placeholder="customer name" formControlName="customer name" autocomplete="off" required>
</mat-form-field>
</td>
<td>
<mat-form-field>
<mat-label>Total</mat-label>
<input matInput placeholder="Total" formControlName="total" autocomplete="off" required>
</mat-form-field>
</td>
</tr>
</div>
</table>
'''<div/>
在这里,我需要一些帮助,以便在特定字段或所有字段在右上角使用Toastr时在右上方显示警报或错误消息
这是formcomponent.ts文件
'''
export class BakeryFormComponent implements OnInit {
@Output() onCancel = new EventEmitter<any>();
@Output() onSubmit = new EventEmitter<any>();
bakeryFormForm: FormGroup
constructor(private fb: FormBuilder,private notification: NotificationService,private dataService: DataService,private router: Router) { }
ngOnInit(): void {
this.bakeryForm = this.fb.group({
customer no: ['',Validators.required],customer name: ['',total: ['',})
}
bakeryCreateForm() {
let data = this.bakeryForm.value
this.dataService.bakeryCreateForm(data)
.subscribe(res => {
this.onSubmit.emit();
this.notification.showSuccess("data entered!...")}
return true
}
}
在这里,当需要使用特定角度的特定字段或所有字段为空时,我需要一些帮助来显示警报或错误消息
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)