多个选择按钮验证在角度2反应验证中不起作用

时间:2017-09-11 05:31:46

标签: angular angular2-forms angular4-forms

只有第一个选择输入字段显示验证红色标记,但第二个仅显示第二个按钮的模糊。但是,两者都必须在没有选择选项的情况下单击提交按钮时显示注释。

请指导我有什么错误,我应该修理什么?



    {
        SaveFileDialog sfd2 = new SaveFileDialog();
        sfd2.Title = "Save as Excel File";
        sfd2.Filter = "Excel Files(2003)|*.xls|Excel Files(2007)|*.xlsx";
        sfd2.FileName = "";

        if (sfd2.ShowDialog() == DialogResult.OK)
        {
            try
            {
                // Excel프로그램을 실행
                excelApp = new Excel.Application();

                // 실행된 Excel프로그램에 통합문서를 추가
                wb = excelApp.Workbooks.Add();
                //텍스트 형식 지정범위
                Excel._Worksheet workSheet = wb.Worksheets.get_Item(1) as Excel._Worksheet;
                Excel.Range oRange;
                oRange = workSheet.get_Range("A1:A300", "S1:S300");
                oRange.Cells.NumberFormat = "@";

                oRange.EntireRow.AutoFit();
                oRange.EntireColumn.AutoFit();
                oRange.WrapText = false;


                //데이터 동시저장
                Map_DataGridView_To_ExcelSheet(dataGridView1, "Sheet1");
                excelApp.Worksheets.Add();                  
                Map_DataGridView_To_ExcelSheet(dataGridView2, "Sheet2");
                excelApp.Worksheets.Add();
                Map_DataGridView_To_ExcelSheet(dataGridView3, "Sheet3");

                //view4에 데이터가 있을때만 4번째 시트를 생성
                if (dataGridView4.DataSource != null)
                {
                    excelApp.Worksheets.Add();
                    Map_DataGridView_To_ExcelSheet(dataGridView4, "Sheet4");
                }

                //excelApp.Worksheets.Add();
                //Map_DataGridView_To_ExcelSheet(dataGridView5, "Sheet5");
                ws.Columns.AutoFit();
                // 여기서 저장경로를 변경하면 됩니다.
               wb.SaveAs(sfd2.FileName, Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
           Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                wb.Close(true);
                excelApp.Quit();     
                MessageBox.Show("저장이 완료되었습니다.");
            }
            //메모리해제
            finally
            {
                releaseObject(ws);
                releaseObject(wb);
                releaseObject(excelApp);
            }
        }
    } 
    private void Map_DataGridView_To_ExcelSheet(DataGridView dataGridView, string sheetName)
    {
        // 지정된 문자열에 해당하는 Sheet를 가져옵니다.
        ws = wb.Worksheets.get_Item(sheetName) as Excel.Worksheet;

    if(dataGridView.DataSource != null)
    {
        for (int i = 0; i < dataGridView.ColumnCount; i++)
        {
            label5.Text = i.ToString();
            for (int j = 0; j < dataGridView.RowCount; j++)
            {
                label6.Text = j.ToString();
                // 워크시트 개체 ws의 Cells(Range 개체)와 DataGridView의 인덱스가 반대인것에 유의
                // 또한, Cells는 인덱스가 1부터 시작
                // ws.Cells[Row, Column]   // dataGridView[Column, Row]
                if (dataGridView[i, j].Value.ToString().Trim() != "")
                {
                    ws.Cells[j + 1, i + 1] = dataGridView[i, j].Value.ToString();
                }
            }
          }
&#13;
import { Component }                          from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'form-detail',
  templateUrl: './form-detail.component.html'
})

export class FormComponent {
  form: FormGroup;
  fruits: any = [
    {"viewValue": "Apple", "value": "apple"},
    {"viewValue": "Mango", "value": "mango"}
  ];
  
  foods: any = [
    {"viewValue": "Food1", "value": "food1"},
    {"viewValue": "Food2", "value": "food2"}
  ];

  constructor(private fb: FormBuilder) {
    this.createForm();
  }

  createForm() {
    this.form = this.fb.group({ 
        fruits: ['', Validators.required ],
        foods: ['', Validators.required ],
      });
  }
  
  onSubmit(){
    if(this.form.valid){
      console.log('valid form');
    }else{
      console.log('invalid form');
   }
  }
}
&#13;
&#13;
&#13;

0 个答案:

没有答案