diff --git a/components/dropdown/dropdown-toggle.directive.ts b/components/dropdown/dropdown-toggle.directive.ts index aecc71366c..fb8f068b45 100644 --- a/components/dropdown/dropdown-toggle.directive.ts +++ b/components/dropdown/dropdown-toggle.directive.ts @@ -1,14 +1,9 @@ import { Directive, ElementRef, Host, HostBinding, HostListener, Input, OnInit } from '@angular/core'; -import { Type } from '@angular/core'; import { DropdownDirective } from './dropdown.directive'; -/* tslint:disable */ -const MouseEvent = (Type as any).MouseEvent as MouseEvent; -/* tslint:enable */ - @Directive({ selector: '[dropdownToggle]', exportAs: 'bs-dropdown-toggle' diff --git a/components/modal/modal.component.ts b/components/modal/modal.component.ts index 23ac5bc08c..fc82225424 100644 --- a/components/modal/modal.component.ts +++ b/components/modal/modal.component.ts @@ -15,13 +15,14 @@ import { Output, Renderer } from '@angular/core'; -import { Type } from '@angular/core'; import { ComponentsHelper } from '../utils/components-helper.service'; import { Utils } from '../utils/utils.class'; import { ModalBackdropComponent, ModalBackdropOptions } from './modal-backdrop.component'; import { ClassName, modalConfigDefaults, ModalOptions, Selector } from './modal-options.class'; +import { window } from '../utils/facade/browser'; + const TRANSITION_DURATION = 300; const BACKDROP_TRANSITION_DURATION = 150; @@ -302,8 +303,7 @@ export class ModalDirective implements AfterViewInit, OnDestroy { /** Scroll bar tricks */ private checkScrollbar():void { - // this._isBodyOverflowing = document.body.clientWidth < window.innerWidth - this.isBodyOverflowing = this.document.body.clientWidth < (Type as any).innerWidth; + this.isBodyOverflowing = this.document.body.clientWidth < window.innerWidth; this.scrollbarWidth = this.getScrollbarWidth(); } diff --git a/components/ng2-bootstrap-config.ts b/components/ng2-bootstrap-config.ts index 34079e51e6..c2a58a4e0f 100644 --- a/components/ng2-bootstrap-config.ts +++ b/components/ng2-bootstrap-config.ts @@ -1,4 +1,5 @@ -import { Type } from '@angular/core'; +import { window } from './utils/facade/browser'; + export enum Ng2BootstrapTheme {BS3 = 1, BS4 = 2} export class Ng2BootstrapConfig { @@ -6,7 +7,7 @@ export class Ng2BootstrapConfig { public static get theme():Ng2BootstrapTheme { // hack as for now - if (Type && (Type as any).__theme === 'bs4') { + if (window.__theme === 'bs4') { return Ng2BootstrapTheme.BS4; } return (this._theme || Ng2BootstrapTheme.BS3); diff --git a/components/rating/rating.component.ts b/components/rating/rating.component.ts index 361d016244..4fce8b661e 100644 --- a/components/rating/rating.component.ts +++ b/components/rating/rating.component.ts @@ -1,13 +1,8 @@ import { Component, EventEmitter, HostListener, Input, OnInit, Output, Self } from '@angular/core'; -import { Type } from '@angular/core'; import { ControlValueAccessor, NgModel } from '@angular/forms'; -/* tslint:disable */ -const KeyboardEvent = (Type as any).KeyboardEvent as KeyboardEvent; -/* tslint:enable */ - @Component({ /* tslint:disable */ selector: 'rating[ngModel]', diff --git a/components/typeahead/typeahead-container.component.ts b/components/typeahead/typeahead-container.component.ts index 46f7e87053..3dacf862d9 100644 --- a/components/typeahead/typeahead-container.component.ts +++ b/components/typeahead/typeahead-container.component.ts @@ -137,7 +137,7 @@ export class TypeaheadContainerComponent { this._active = value; } - protected hightlight(item:any, query:string):string { + protected hightlight(item:any, query:any):string { let itemStr:string = TypeaheadUtils.getValueFromObject(item, this._field); let itemStrHelper:string = (this.parent.typeaheadLatinize ? TypeaheadUtils.latinize(itemStr) diff --git a/components/typeahead/typeahead.directive.ts b/components/typeahead/typeahead.directive.ts index 6e92986a8a..d3e3428a1b 100644 --- a/components/typeahead/typeahead.directive.ts +++ b/components/typeahead/typeahead.directive.ts @@ -17,11 +17,7 @@ import 'rxjs/add/operator/map'; import 'rxjs/add/operator/mergeMap'; import 'rxjs/add/operator/toArray'; -import { Type } from '@angular/core'; import { ComponentsHelper } from '../utils/components-helper.service'; -/* tslint:disable */ -const KeyboardEvent = (Type as any).KeyboardEvent as KeyboardEvent; -/* tslint:enable */ @Directive({ /* tslint:disable */ diff --git a/components/utils/components-helper.service.ts b/components/utils/components-helper.service.ts index c73ac51781..bf16a4d30c 100644 --- a/components/utils/components-helper.service.ts +++ b/components/utils/components-helper.service.ts @@ -66,8 +66,11 @@ export class ComponentsHelper { providers?:ResolvedReflectiveProvider[]):ComponentRef { let componentFactory = this.componentFactoryResolver.resolveComponentFactory(ComponentClass); let parentInjector = location.parentInjector; - let childInjector = providers !== undefined && providers.length > 0 ? - ReflectiveInjector.fromResolvedProviders(providers, parentInjector) : parentInjector; + let childInjector: Injector = parentInjector; + if (providers && providers.length > 0) { + childInjector = ReflectiveInjector.fromResolvedProviders(providers, parentInjector); + } + return location.createComponent(componentFactory, location.length, childInjector); } diff --git a/components/utils/facade/browser.ts b/components/utils/facade/browser.ts new file mode 100644 index 0000000000..6c84c0535c --- /dev/null +++ b/components/utils/facade/browser.ts @@ -0,0 +1,26 @@ +/*tslint:disable */ +/** + * @license + * Copyright Google Inc. All Rights Reserved. + * + * Use of this source code is governed by an MIT-style license that can be + * found in the LICENSE file at https://angular.io/license + */ + +/** + * JS version of browser APIs. This library can only run in the browser. + */ +var win = typeof window !== 'undefined' && window || {}; + +export {win as window}; +export var document = win.document; +export var location = win.location; +export var gc = win['gc'] ? () => win['gc']() : (): any => null; +export var performance = win['performance'] ? win['performance'] : null; +export const Event = win['Event']; +export const MouseEvent = win['MouseEvent']; +export const KeyboardEvent = win['KeyboardEvent']; +export const EventTarget = win['EventTarget']; +export const History = win['History']; +export const Location = win['Location']; +export const EventListener = win['EventListener']; diff --git a/components/utils/utils.class.ts b/components/utils/utils.class.ts index 9410d03828..78eb4d2c4c 100644 --- a/components/utils/utils.class.ts +++ b/components/utils/utils.class.ts @@ -1,19 +1,19 @@ -import { Type } from '@angular/core'; +import { window } from './facade/browser'; export class Utils { - public static reflow(element:any):void { + public static reflow(element: any): void { new Function('bs', 'return bs')(element.offsetHeight); } // source: https://github.com/jquery/jquery/blob/master/src/css/var/getStyles.js - public static getStyles(elem:any):any { + public static getStyles(elem: any): any { // Support: IE <=11 only, Firefox <=30 (#15098, #14150) // IE throws on elements created in popups // FF meanwhile throws on frame elements through "defaultView.getComputedStyle" let view = elem.ownerDocument.defaultView; if (!view || !view.opener) { - view = Type; + view = window; } return view.getComputedStyle(elem);