Angular 在角度应用中自动触发IE 10/11的角度材料错误状态匹配器
当Angular 6应用程序在IE 11上打开时,表单输入验证会自动触发,即使我没有触摸任何表单输入字段。我更新了polyfills.ts文件以支持Internet Explorer,但没有按预期工作。对于所有其他浏览器,它工作正常,只有在InternetExplorer11中,它没有正确加载Angular应用程序 我尝试以下方法Angular 在角度应用中自动触发IE 10/11的角度材料错误状态匹配器,angular,angular6,angular-material2,angular-forms,angular-material-6,Angular,Angular6,Angular Material2,Angular Forms,Angular Material 6,当Angular 6应用程序在IE 11上打开时,表单输入验证会自动触发,即使我没有触摸任何表单输入字段。我更新了polyfills.ts文件以支持Internet Explorer,但没有按预期工作。对于所有其他浏览器,它工作正常,只有在InternetExplorer11中,它没有正确加载Angular应用程序 我尝试以下方法 // Custom Error State Matcher import { FormControl, FormGroupDirective, NgForm } f
// Custom Error State Matcher
import { FormControl, FormGroupDirective, NgForm } from
"@angular/forms";
import { ErrorStateMatcher } from "@angular/material/core";
导出类CustomErrorStateMatcher实现ErrorStateMatcher{
isErrorState(控件:FormControl | null,形式:FormGroupDirective |
NgForm | null):布尔值{
const issubmitt=form&&form.submitted;
return!!(control&&control.invalid&&(control.dirty)|
control.toucted | | issubmited));
}
}
//test.component.ts
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { CustomErrorStateMatcher } from '../error-control';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
exampleForm: FormGroup;
matcher = new CustomErrorStateMatcher();
constructor(private fb: FormBuilder) { }
ngOnInit() {
this.exampleForm = this.fb.group({
firstName: ['', [Validators.required]],
lastName: ['', [Validators.required]],
email: ['', [Validators.required, Validators.email]]
});
}
examleFormSubmit() {
return false;
}
}
//test.component.html
div class="container">
<form [formGroup]="exampleForm" (ngSubmit)="examleFormSubmit()">
<mat-form-field appearance="outline" [hideRequiredMarker]="true">
<mat-label>First Name</mat-label>
<input type="text" matInput placeholder="Enter first name" formControlName="firstName" [errorStateMatcher]="matcher">
</mat-form-field>
<mat-form-field appearance="outline" [hideRequiredMarker]="true">
<mat-label>Email Address</mat-label>
<input type="text" matInput placeholder="Enter last name" formControlName="lastName" [errorStateMatcher]="matcher">
</mat-form-field>
<mat-form-field appearance="outline" [hideRequiredMarker]="true">
<mat-label>Email Address</mat-label>
<input type="email" matInput placeholder="Enter email address" formControlName="email" [errorStateMatcher]="matcher">
</mat-form-field>
<div class="submit-form">
<button type="submit" mat-raised-button class="submit-button"> .
<span>Submit</span></button>
</div>
</form>
</div>
//Updated polyfills.ts(for Internet Explorer 11 support)
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';
/** IE10 and IE11 requires the following for NgClass support on SVG
elements */
import 'classlist.js';
/** IE10 and IE11 requires the following for the Reflect API. */
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
`@angular/platform-browser/animations`
import 'web-animations-js';
import 'zone.js/dist/zone';
//test.component.ts
从“@angular/core”导入{Component,OnInit};
从“@angular/forms”导入{FormBuilder、FormGroup、Validators};
从“../error control”导入{CustomErrorStateMatcher};
@组成部分({
选择器:“应用程序测试”,
templateUrl:'./test.component.html',
样式URL:['./test.component.css']
})
导出类TestComponent实现OnInit{
示例形式:FormGroup;
matcher=新的CustomErrorStateMatcher();
构造函数(私有fb:FormBuilder){}
恩戈尼尼特(){
this.exampleForm=this.fb.group({
名字:[''[Validators.required]],
lastName:[''[Validators.required]],
电子邮件:[''[Validators.required,Validators.email]]
});
}
examleFormSubmit(){
返回false;
}
}
//test.component.html
div class=“container”>
名字
电子邮件地址
电子邮件地址
.
提交
//更新的polyfills.ts(用于Internet Explorer 11支持)
/**IE9、IE10和IE11需要以下所有多填充**/
导入“核心js/es6/symbol”;
导入“核心js/es6/object”;
导入“核心js/es6/功能”;
导入“core js/es6/parse int”;
导入“core js/es6/parse float”;
导入“core js/es6/number”;
导入“core js/es6/math”;
导入“core js/es6/string”;
导入“core js/es6/date”;
导入“core js/es6/array”;
导入“core js/es6/regexp”;
导入“核心js/es6/map”;
导入“核心js/es6/弱映射”;
导入“core js/es6/set”;
/**IE10和IE11要求在SVG上支持NgClass
元素*/
导入“classlist.js”;
/**IE10和IE11要求反射API满足以下要求*/
导入“core js/es6/reflect”;
导入“core js/es7/reflect”;
`@角度/平台浏览器/动画`
导入“web动画js”;
导入'zone.js/dist/zone';
当Angular 6应用程序在IE 11上打开时,是否有任何方法限制表单输入验证的自动触发。如果有人对此有任何想法,请建议我
提前谢谢