ngForm simple example in angular 6 with select box

前端 未结 1 869
庸人自扰
庸人自扰 2021-01-20 03:18

Angular 6 form validation simple example. With email validation and select box(drop down).ngForm simple example in angular 6 with select box

1条回答
  •  没有蜡笔的小新
    2021-01-20 03:32

    Use ngForm. Import it your component.module.ts(module file)

    import { FormsModule } from '@angular/forms';
    

    Add it your component template

    Name is required
    Email is required
    Email is invalid

    Add it your component.ts

    allnames = [{
        name_id: 1,
        name: 'Jhon'
    }, {
        name_id: 2,
        name: 'Chena'
    }, {
        name_id: 3,
        name: 'Jack'
    }]
    model: any = {};
    ngOnInit() {
        this.model.name_id = 2;
    }
    

    The name Chena is selected in select box and email valid. It's work well. And i will use it.

    0 讨论(0)
提交回复
热议问题