mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
committed by
Andrew Seguin
parent
f9bd5d4bb5
commit
5d437ea861
@@ -145,7 +145,7 @@ export class MdOption {
|
||||
focus(): void {
|
||||
const element = this._getHostElement();
|
||||
|
||||
if ('focus' in element) {
|
||||
if (typeof element.focus === 'function') {
|
||||
element.focus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user