【发布时间】:2020-03-10 12:00:58
【问题描述】:
我发现有一个IE bug,设置占位符是调用输入事件为described here。这发生在页面加载时,因此没有用户交互。
我的代码:
app.component.html
<mat-form-field>
<input matInput placeholder="test" (input)="onValueChange('test')">
</mat-form-field>
app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
ngOnInit() {
}
onValueChange(value: string) {
console.log("should not be in here");
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatDialogModule } from '@angular/material/dialog';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatCardModule } from '@angular/material/card';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
MatCardModule, MatFormFieldModule, MatInputModule, MatDialogModule, BrowserAnimationsModule, MatExpansionModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
浏览器列表 (注意IE 9-11已启用)
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11 # For IE 9-11 support, remove 'not'.
tsconfig.json (注意es5)
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es5",
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
这里是the stackblitz project,但是不能用IE11调试。在我的真实项目中,我有一个ngFor,它创建了多个输入元素。
有解决办法吗?
证明问题
ng 版本
Angular CLI: 8.3.22
Node: 10.14.2
OS: win32 x64
Angular: 8.2.14
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.803.22
@angular-devkit/build-angular 0.803.22
@angular-devkit/build-optimizer 0.803.22
@angular-devkit/build-webpack 0.803.22
@angular-devkit/core 8.3.22
@angular-devkit/schematics 8.3.22
@angular/cdk 7.3.6
@angular/cli 8.3.22
@angular/material 7.3.6
@ngtools/webpack 8.3.22
@schematics/angular 8.3.22
@schematics/update 0.803.22
rxjs 6.5.4
typescript 3.5.3
webpack 4.39.2
分步说明
-
ng new test(无 Angular 路由,SCSS) - 替换app.component.html和app.component.ts(添加
mat-form-field和onValueChange()) - 将
MatFormFieldModule、MatInputModule和BrowserAnimationsModule添加到app.module.ts -
ng add @angular/material(靛蓝粉色,没有 HammerJS,有浏览器动画) - 编辑 browserlist(删除 IE 9-11 行的 NOT)
- 在 tsconfig.json 中将
target设置为es5
【问题讨论】:
标签: angular angular-material internet-explorer-11 placeholder mat-input