javascript – Angular Material md-select没有显示错误
作者:互联网
我正在尝试实现一个表单,其中错误消息在单击提交按钮之前不会显示.对于输入,这似乎是开箱即用的,但对于md-select不符合预期.
当我提交表单(没有填写任何内容)时,我收到输入的错误消息,但不是md-select的错误消息.
http://plnkr.co/edit/BDB0NVccWckqgnSYD9Qt?p=preview
这是表格:
<form name="userForm" novalidate ng-submit="test()">
<md-input-container>
<label>Last Name</label>
<input name="lastName" ng-model="lastName" required>
<div ng-messages="userForm.lastName.$error">
<div ng-message='required'>This is required!</div>
</div>
</md-input-container>
<md-input-container class="md-block">
<label>Favorite Number</label>
<md-select name="favoriteNumber" ng-model="myNumber" required>
<md-option value="1">One</md-option>
<md-option value="2">Two</md-option>
</md-select>
<div ng-messages="userForm.favoriteNumber.$error">
<div ng-message='required'>This is required</div>
</div>
</md-input-container>
<div>name = {{lastName}}</div>
<div>userForm.lastName.$error = {{userForm.lastName.$error}}</div>
<div>number = {{myNumber}}</div>
<div>userForm.favoriteNumber.$error = {{userForm.favoriteNumber.$error}} </div>
<md-button type="submit" class="md-raised md-primary">Save</md-button>
</form>
请注意,这是从Angular Material 1.1.1开始修复的
解决方法:
关于这个github issue有一个问题
基本上,当md-select模糊时,消息就会显示出来
标签:javascript,angularjs,angular-material 来源: https://codeday.me/bug/20190715/1465759.html