Closed
Description
Bug, feature request, or proposal:
Bug
What is the expected behavior?
We are using dynamically generating forms for a line of business application and when we added in Angular Material the form elements would throw an error when being added to the page.
The error is as follows
ERROR TypeError: Cannot read property 'invalid' of null
at MdInput.defaultErrorStateMatcher [as errorStateMatcher] (material.es5.js:2420)
at MdInput.webpackJsonp.../../../material/@angular/material.es5.js.MdInput._updateErrorState
We were able to fix it by changing the defaultErrorStateMatcher
method in material.es5.js
to also check for the presence of control
before performing additional verifications.
function defaultErrorStateMatcher(control, form) {
var /** @type {?} */ isSubmitted = form && form.submitted;
return !!(control && control.invalid && (control.touched || isSubmitted));
}
What is the current behavior?
The error above is thrown.
What are the steps to reproduce?
Providing a StackBlitz/Plunker (or similar) is the best way to get the team to see your issue.
Plunker starter (using on @master
): https://goo.gl/DlHd6U
StackBlitz starter (using latest npm
release): https://goo.gl/wwnhMV
What is the use-case or motivation for changing an existing behavior?
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Our versions are as follows
"@angular/animations": "^4.3.0",
"@angular/cdk": "^2.0.0-beta.10",
"@angular/common": "^4.3.0",
"@angular/compiler": "^4.3.0",
"@angular/compiler-cli": "^4.3.0",
"@angular/core": "^4.3.0",
"@angular/flex-layout": "^2.0.0-beta.9",
"@angular/forms": "^4.3.0",
"@angular/http": "^4.3.0",
"@angular/material": "^2.0.0-beta.10",
"@angular/platform-browser": "^4.3.0",
"@angular/platform-browser-dynamic": "^4.3.0",
"@angular/platform-server": "^4.3.0",
"@angular/router": "^4.3.0",
"@types/file-saver": "0.0.0",
and
"@angular/cli": "^1.3.1",
"@angular/compiler-cli": "^2.4.0",
...
"ts-node": "~2.0.0",
"tslint": "~4.4.2",
"typescript": "~2.3.2"