refactor: remove usages of if in checks (#6436)

This is something that came up in https://github.com/angular/material2/pull/2907#discussion_r130968388. We shouldn't be using the `if ('someString' in obj)` checks, because they can be broken by minifiers that rename class members.
This commit is contained in:
Kristiyan Kostadinov
2017-08-15 23:48:08 +02:00
committed by Andrew Seguin
parent f9bd5d4bb5
commit 5d437ea861
4 changed files with 6 additions and 4 deletions
+1 -1
View File
@@ -145,7 +145,7 @@ export class MdOption {
focus(): void {
const element = this._getHostElement();
if ('focus' in element) {
if (typeof element.focus === 'function') {
element.focus();
}
}
+3 -1
View File
@@ -278,7 +278,9 @@ export class MdDatepicker<D> implements OnDestroy {
if (this._calendarPortal && this._calendarPortal.isAttached) {
this._calendarPortal.detach();
}
if (this._focusedElementBeforeOpen && 'focus' in this._focusedElementBeforeOpen) {
if (this._focusedElementBeforeOpen &&
typeof this._focusedElementBeforeOpen.focus === 'function') {
this._focusedElementBeforeOpen.focus();
this._focusedElementBeforeOpen = null;
}
+1 -1
View File
@@ -150,7 +150,7 @@ export class MdDialogContainer extends BasePortalHost {
const toFocus = this._elementFocusedBeforeDialogWasOpened;
// We need the extra check, because IE can set the `activeElement` to null in some cases.
if (toFocus && 'focus' in toFocus) {
if (toFocus && typeof toFocus.focus === 'function') {
toFocus.focus();
}
+1 -1
View File
@@ -699,7 +699,7 @@ describe('MdSlideToggle with forms', () => {
}));
it('should prevent the form from submit when being required', () => {
if ('reportValidity' in inputElement === false) {
if (typeof (inputElement as any).reportValidity === 'undefined') {
// If the browser does not report the validity then the tests will break.
// e.g Safari 8 on Mobile.
return;