简体   繁体   中英

ng-show show error when input is empty

Ok i have :

<div class="form-group">
<label for="address" class="control-label col-lg-5 col-md-6">                                @Html.Label(@Translator.Translate("STREET_ADDRESS")):
<span ng-show="editUserForm.Address.$error.required" class="required">*</span>
</label>
<div class="col-lg-7 col-md-6">
@Html.TextBoxFor(m => m.Address, new {name="Address", @class = "form-control", id = "address", @maxlength = "30", ng_model = "address", @required = "required", ng_pattern = @"/[A-Za-z]+ ?[0-9]+$/" })
</div>
</div>

So my idea is when this textbox is empty that show * but for me it not working...Any help?

(移自评论)将跨度更改为:

<span ng-show="!address">*</span>

尝试这个

   <span ng-show="editUserForm.Address.$dirty && editUserForm.Address.$error.required" class="required">*</span>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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