简体   繁体   English

如何在Angular2中进行自动完成验证?

[英]How to do autocomplete validation in Angular2?

I have been trying to implement an auto-complete to an input in my form in angular2. 我一直在尝试在angular2中以我的形式对输入实现自动完成。 I want to show second hidden div if the input is invalid. 如果输入无效,我想显示第二个隐藏的div。 Could you help me how to do that please? 你能帮帮我怎么做吗?

<div class="form-group">
<div *ngSwitchCase="'organisation'">
    <label [attr.for]="parameter.ObjectID" [innerHtml]="parameter.paramLabel">  </label>
    <input [id]='parameter.ObjectID' class="form-control" type="text" [(ngModel)]="parameter.value" (keyup)="filter()" (change)="filter()" (blur)="filter()" [required]="parameter.mandatory" name="mandatory" #mandatory="ngModel">
    <div *ngIf="companyNames.length > 0">
        <ul *ngFor="let item of filteredCompanyList">
            <li>
                <a (click)="select(item)">{{item}}</a>
            </li>
        </ul>
    </div>
    <div [hidden]="!parameter.mandatory || mandatory.valid || mandatory.pristine" class="alert alert-danger">Please do not leave this field blank</div>
    <div [hidden]="temp(mandatory)" class="alert alert-danger">The organisation entered was either not found or does not subscribe to the product</div>
</div>

The second hidden div will be displayed if your function temp() returns false. 如果函数temp()返回false,将显示第二个隐藏的div。

All your checks (input valid?) you have to do in this function. 您必须在此功能中进行所有检查(输入有效吗?)。

UPDATE: 更新:

Just use this [hidden]="filteredCompanyList.length > 0" to show/hide your div. 只需使用[hidden]="filteredCompanyList.length > 0"来显示/隐藏你的div。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM