angular - 初始化表单时未禁用Angular7按钮
问题描述
我正在尝试在未填写表单时禁用按钮。在 Chrome 和 FF 中一切正常,但在 IE11 中,该按钮仍处于启用状态。那是代码:
<div class="col-12">
<app-button label="login.login" (click)="save()" [disabled]="(!f.dirty || f.invalid) ? 'disable' : null"></app-button>
<div class="pt-3 text-right">
<a [routerLink]="['/login']" class="pt-5">{{"login.changepassword" | translate}}</a>
</div>
</div>
奇怪的是,如果我在通过浏览器检查器 (F12) 生成的 html 中进行最小的更改(例如,更改标签),它会完美运行。
解决方案
尝试通过添加 @Input 装饰器来检测何时必须禁用按钮来遵循方法。
组件 app-button.component.ts
selector:['app-button'],
templeateUrl: ['./app-buton.component.html']
....
Class ButtonComponent {
@Input isDisabled: booelan
}
组件 app-button.component.html
<button [disabled]="isDisabled">
然后现在应用程序按钮组件的实现位置,您需要执行以下代码:
<app-button [isDisabled]="(!f.dirty || !f.valid)"> </app-button>
推荐阅读
- java - 通过 Google Classroom API 创建教师时,请求的身份验证范围不足错误
- ios - 如何正确设置数据访问以使用 Realm Swift(非同步)查询 MongoDB
- rust - Vec::new() 如何知道请求的元素类型是什么?
- java - 如何将 applicationContext.xml 和 Bean 从外部 jar 导入到@SpringBootTest?
- css - 如何通过css使用/访问斜体替代字体字母?
- xamarin - 需要在 Dev Express Xamarin 表单中将月份视图显示为“1 Sep”
- database - 如何在 DBeaver 中设置自动连接 .csv 文件的数据类型?
- php - 在 Wordpress 的自定义模板中显示自定义帖子
- python - 将安全组设置为 ALB aws
- python - 如何使用正则表达式查找一个字符超过 1 次?