我在表单中设置了md-select,md-option可以手动选择,也可以由其他组件自动填充。问题是,如果我手动填写所有必需的输入,提交按钮可能会被禁用,但是如果我使用其他组件自动填充这些字段,有时md-select没有值,按钮仍然可以单击。
<md-select [userData]="'patient.title'" placeholder="Title" class="full-width" name="title" [(ngModel)]="user.title" required>
<md-option *ngFor="let title of titles" [value]="title.Label">
{{ title.Label }}
</md-option>
</md-select>发布于 2018-09-11 17:24:27
您可以像这样使用ng-disabled指令:
创建布尔变量disableUserDataSelect。在您的代码中,当md-select没有值时,将disableDataSelect设置为false (或者,当您想要禁用选择时,通常设置为false)。然后更改md的html -选择添加ng-disabled="disableUserDataSelect"“,如下所示:
<md-select ng-disabled="disableUserDataSelect" [userData]="'patient.title'" placeholder="Title" class="full-width" name="title" [(ngModel)]="user.title" required>
<md-option *ngFor="let title of titles" [value]="title.Label">
{{ title.Label }}
</md-option>
</md-select>这样,当您需要时,您的选择将被禁用。
检查这个问题:
https://stackoverflow.com/questions/52272474
复制相似问题