加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何将所需的验证应用于角度2的下拉列表

发布时间:2020-12-17 07:14:47 所属栏目:安全 来源:网络整理
导读:我正在使用select html标签,我是绑定列表.如果未选择下拉列表并在其标题上显示“选择”,则需要进行必要的验证. 解决方法 我使用了* ngIf语法,但您可以在下拉列表中提供以下验证: div class="form-group" div label for="country"Country*:/label /div div n
我正在使用select html标签,我是绑定列表.如果未选择下拉列表并在其标题上显示“选择”,则需要进行必要的验证.

解决方法

我使用了* ngIf语法,但您可以在下拉列表中提供以下验证:

<div class="form-group">
    <div>
        <label for="country">Country*:</label>
    </div>
    <div ng-class="{'valid':country.$valid}">
        <select class="form-control" name='country' [(ngModel)]='fd.country' required>
            <option *ngFor="let obj of country" [ngValue]="obj">{{obj}}</option>
        </select>
    </div>
    <small *ngIf="(myForm._submitted && !country.valid && !fd.country) || (!country.valid && country.dirty) ">Required (Please select country).</small>
</div>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读