我有4個複選框,其中至少有一個應該由用戶選擇。由於我是Angular 2的新手,所以有人可以幫我解決這個問題嗎?如何在複選框組中添加必需的字段驗證?
更新的代碼片斷:
HTML
<b><label *ngFor="let type of topics;let i=index" class="checkbox-inline">
<input type="checkbox" id="{{'chkPhysician'+i}}" name="chekType"
formControlName="types" [value]="type.value" />
{{type.display}}
</label>
component.ts
public topics = [
{ value: 'test1', display: 'test1',selected:true },
{ value: 'test2', display: 'test2',selected:true },
{ value: 'test3', display: 'test3',selected:true },
{ value: 'test4', display: 'test4',selected:true },
];
constructor(private fb: FormBuilder) { }
ngOnInit(): void {
this.mirForm = this.fb.group({
date: [this.date, Validators.required],
Name: ['', [Validators.required, Validators.minLength(4)]],
Mobile: ['', [Validators.required, Validators.minLength(10)]],
Email: ['', [Validators.required, Validators.pattern('[a-zA-Z0-9._%+-][email protected][a-zA-Z0-9.-]+')]],
types:'', etc..............
Kiruba你好,請加你到目前爲止的代碼,以便其他用戶對您所上 –
@ amura.cxg我已經添加了示例代碼的工作是什麼一些背景。 – Kirubakaran