html 带有验证的Angular 6反应形式(Bootstrap 3类)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 带有验证的Angular 6反应形式(Bootstrap 3类)相关的知识,希望对你有一定的参考价值。
import { ToastService } from 'Services/toast.service';
import { Component, OnInit, OnChanges, Input, ViewChild, Output, EventEmitter, SimpleChanges, OnDestroy } from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { CaseActionService } from 'App/services/case-status.service';
@Component({
selector: 'v-case-action',
templateUrl: './case-action.component.html',
styleUrls: [ './case-action.component.scss' ],
})
export class CaseActionComponent implements OnInit {
myForm: FormGroup;
state = {
case_id: null,
};
constructor(
private toastService: ToastService,
private caseActionService: CaseActionService,
private fb: FormBuilder
) {
}
ngOnInit(): void {
this.myForm = this.fb.group({
remarks: ['', Validators.required],
});
}
onSubmit(form: FormGroup) {
const remarks = form.value.remarks;
// stop if form invalid
if (this.myForm.invalid) {
return;
}
this.rejectCase(remarks);
}
rejectCase(remarks) {
this.caseActionService.reject(this.state.case_id, remarks)
.pipe(finalize(() => console.log(1)))
.subscribe(
res => {
console.log(res);
this.toastService.show('success', { title: 'Success Reject Rcu Case' });
},
err => {
console.log('err', err);
this.toastService.show('error', { title: 'Error Reject Rcu Case' });
});
}
}
<form [formGroup]="myForm" (ngSubmit)="onSubmit(myForm)">
<h4 class="">Action Remarks</h4>
<div class="form-group" [ngClass]="{ 'has-error has-feedback': myForm.get('remarks').touched && myForm.get('remarks').invalid }">
<label class="control-label">
<h6>Remarks <span>*</span></h6>
</label>
<textarea formControlName="remarks" class="form-control" rows="10"></textarea>
<span *ngIf="myForm.get('remarks').touched && myForm.get('remarks').hasError('required')" class="help-block">Please provide a remarks!</span>
</div>
<button type="submit" [disabled]="myForm.invalid" class="btn btn-primary">Submit</button>
</form>
以上是关于html 带有验证的Angular 6反应形式(Bootstrap 3类)的主要内容,如果未能解决你的问题,请参考以下文章
[密码并以角度8的反应形式确认密码验证
Angular2反应形式表
我想编写可用于任何角度形式的通用验证-法向反应已经完成并且可以正常工作
订阅多个字段的 valueChanges 导致反应形式 angular 2 的性能问题
html Angular:反应表单和表单验证
我想编写可以以任何角度形式使用的通用验证 - 正常反应已经完成并且工作正常