From 9271650303b8666494303ab59b99bbd9c792f329 Mon Sep 17 00:00:00 2001 From: mwe Date: Thu, 1 Sep 2016 17:16:45 +0200 Subject: [PATCH 1/3] use "windows" instead of "Type" for the "global" substitutions --- components/dropdown/dropdown-toggle.directive.ts | 5 ----- components/modal/modal.component.ts | 4 +--- components/ng2-bootstrap-config.ts | 3 +-- components/rating/rating.component.ts | 5 ----- components/typeahead/typeahead.directive.ts | 4 ---- components/utils/components-helper.service.ts | 14 ++++++++++---- components/utils/utils.class.ts | 4 +--- 7 files changed, 13 insertions(+), 26 deletions(-) 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..967839bb57 100644 --- a/components/modal/modal.component.ts +++ b/components/modal/modal.component.ts @@ -15,7 +15,6 @@ import { Output, Renderer } from '@angular/core'; -import { Type } from '@angular/core'; import { ComponentsHelper } from '../utils/components-helper.service'; import { Utils } from '../utils/utils.class'; @@ -302,8 +301,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..96d0e636db 100644 --- a/components/ng2-bootstrap-config.ts +++ b/components/ng2-bootstrap-config.ts @@ -1,4 +1,3 @@ -import { Type } from '@angular/core'; export enum Ng2BootstrapTheme {BS3 = 1, BS4 = 2} export class Ng2BootstrapConfig { @@ -6,7 +5,7 @@ export class Ng2BootstrapConfig { public static get theme():Ng2BootstrapTheme { // hack as for now - if (Type && (Type as any).__theme === 'bs4') { + if ((window as any).__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.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..fae8bc7f2b 100644 --- a/components/utils/components-helper.service.ts +++ b/components/utils/components-helper.service.ts @@ -1,6 +1,6 @@ import { - ApplicationRef, ComponentFactoryResolver, ComponentRef, Injectable, Injector, ReflectiveInjector, ViewContainerRef, - ResolvedReflectiveProvider, Type + ApplicationRef, ComponentFactoryResolver, ComponentRef, Injectable, Injector, ReflectiveInjector, + ResolvedReflectiveProvider, Type, ViewContainerRef } from '@angular/core'; import { DOCUMENT } from '@angular/platform-browser'; @@ -66,8 +66,14 @@ 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; + + if (providers && providers.length > 0) { + childInjector = ReflectiveInjector.fromResolvedProviders(providers, parentInjector); + } else { + childInjector = parentInjector; + } + return location.createComponent(componentFactory, location.length, childInjector); } diff --git a/components/utils/utils.class.ts b/components/utils/utils.class.ts index 9410d03828..60921dcd81 100644 --- a/components/utils/utils.class.ts +++ b/components/utils/utils.class.ts @@ -1,5 +1,3 @@ -import { Type } from '@angular/core'; - export class Utils { public static reflow(element:any):void { new Function('bs', 'return bs')(element.offsetHeight); @@ -13,7 +11,7 @@ export class Utils { let view = elem.ownerDocument.defaultView; if (!view || !view.opener) { - view = Type; + view = window; } return view.getComputedStyle(elem); From 68bee5f345eb25fa6cbcb249253d57cb2c037c97 Mon Sep 17 00:00:00 2001 From: mwe Date: Thu, 1 Sep 2016 17:27:13 +0200 Subject: [PATCH 2/3] rollback some changes for universal renderer --- components/dropdown/dropdown-toggle.directive.ts | 4 ++++ components/modal/modal.component.ts | 2 +- components/ng2-bootstrap-config.ts | 2 +- components/rating/rating.component.ts | 4 ++++ components/typeahead/typeahead.directive.ts | 4 ++++ components/utils/utils.class.ts | 2 +- 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/components/dropdown/dropdown-toggle.directive.ts b/components/dropdown/dropdown-toggle.directive.ts index fb8f068b45..c34a1d389e 100644 --- a/components/dropdown/dropdown-toggle.directive.ts +++ b/components/dropdown/dropdown-toggle.directive.ts @@ -4,6 +4,10 @@ import { import { DropdownDirective } from './dropdown.directive'; +/* tslint:disable */ +const MouseEvent = (window 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 967839bb57..afea3235ac 100644 --- a/components/modal/modal.component.ts +++ b/components/modal/modal.component.ts @@ -301,7 +301,7 @@ export class ModalDirective implements AfterViewInit, OnDestroy { /** Scroll bar tricks */ private checkScrollbar():void { - this.isBodyOverflowing = this.document.body.clientWidth < window.innerWidth; + this.isBodyOverflowing = this.document.body.clientWidth < (window as any).innerWidth; this.scrollbarWidth = this.getScrollbarWidth(); } diff --git a/components/ng2-bootstrap-config.ts b/components/ng2-bootstrap-config.ts index 96d0e636db..f28281d50f 100644 --- a/components/ng2-bootstrap-config.ts +++ b/components/ng2-bootstrap-config.ts @@ -5,7 +5,7 @@ export class Ng2BootstrapConfig { public static get theme():Ng2BootstrapTheme { // hack as for now - if ((window as any).__theme === 'bs4') { + if (window && (window as any).__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 4fce8b661e..f497c71741 100644 --- a/components/rating/rating.component.ts +++ b/components/rating/rating.component.ts @@ -3,6 +3,10 @@ import { } from '@angular/core'; import { ControlValueAccessor, NgModel } from '@angular/forms'; +/* tslint:disable */ +const KeyboardEvent = (window as any).KeyboardEvent as KeyboardEvent; +/* tslint:enable */ + @Component({ /* tslint:disable */ selector: 'rating[ngModel]', diff --git a/components/typeahead/typeahead.directive.ts b/components/typeahead/typeahead.directive.ts index d3e3428a1b..7ff0ee172e 100644 --- a/components/typeahead/typeahead.directive.ts +++ b/components/typeahead/typeahead.directive.ts @@ -19,6 +19,10 @@ import 'rxjs/add/operator/toArray'; import { ComponentsHelper } from '../utils/components-helper.service'; +/* tslint:disable */ +const KeyboardEvent = (window as any).KeyboardEvent as KeyboardEvent; +/* tslint:enable */ + @Directive({ /* tslint:disable */ selector: '[typeahead][ngModel],[typeahead][formControlName]' diff --git a/components/utils/utils.class.ts b/components/utils/utils.class.ts index 60921dcd81..1d11082ceb 100644 --- a/components/utils/utils.class.ts +++ b/components/utils/utils.class.ts @@ -11,7 +11,7 @@ export class Utils { let view = elem.ownerDocument.defaultView; if (!view || !view.opener) { - view = window; + view = (window as any); } return view.getComputedStyle(elem); From f00c5e35c8da729112b78df9e2ce059759e4143c Mon Sep 17 00:00:00 2001 From: mwe Date: Thu, 1 Sep 2016 19:04:52 +0200 Subject: [PATCH 3/3] solution for https://github.com/valor-software/ng2-bootstrap/pull/888 --- .../typeahead/typeahead-container.component.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/typeahead/typeahead-container.component.ts b/components/typeahead/typeahead-container.component.ts index 46f7e87053..f6a7328f56 100644 --- a/components/typeahead/typeahead-container.component.ts +++ b/components/typeahead/typeahead-container.component.ts @@ -43,14 +43,14 @@ const TEMPLATE:any = {
  • - -