Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use "window" instead of "Type" for the "global" substitutions #909

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions components/dropdown/dropdown-toggle.directive.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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;
const MouseEvent = (window as any).MouseEvent as MouseEvent;
/* tslint:enable */

@Directive({
Expand Down
4 changes: 1 addition & 3 deletions components/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 as any).innerWidth;
this.scrollbarWidth = this.getScrollbarWidth();
}

Expand Down
3 changes: 1 addition & 2 deletions components/ng2-bootstrap-config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { Type } from '@angular/core';
export enum Ng2BootstrapTheme {BS3 = 1, BS4 = 2}

export class Ng2BootstrapConfig {
private static _theme:Ng2BootstrapTheme;

public static get theme():Ng2BootstrapTheme {
// hack as for now
if (Type && (Type as any).__theme === 'bs4') {
if (window && (window as any).__theme === 'bs4') {
return Ng2BootstrapTheme.BS4;
}
return (this._theme || Ng2BootstrapTheme.BS3);
Expand Down
3 changes: 1 addition & 2 deletions components/rating/rating.component.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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;
const KeyboardEvent = (window as any).KeyboardEvent as KeyboardEvent;
/* tslint:enable */

@Component({
Expand Down
16 changes: 8 additions & 8 deletions components/typeahead/typeahead-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ const TEMPLATE:any = {
<li *ngFor="let match of matches; let i = index"
[class.active]="isActive(match)"
(mouseenter)="selectActive(match)">
<a href="#"
*ngIf="!itemTemplate"
(click)="selectMatch(match, $event)"
tabindex="-1"
<a href="#"
*ngIf="!itemTemplate"
(click)="selectMatch(match, $event)"
tabindex="-1"
[innerHtml]="hightlight(match, query)"></a>
<a href="#"
*ngIf="itemTemplate"
(click)="selectMatch(match, $event)"
<a href="#"
*ngIf="itemTemplate"
(click)="selectMatch(match, $event)"
tabindex="-1">
<template [ngTemplateOutlet]="itemTemplate"
[ngOutletContext]="{item: match, index: i}">
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions components/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ 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;
const KeyboardEvent = (window as any).KeyboardEvent as KeyboardEvent;
/* tslint:enable */

@Directive({
Expand Down
14 changes: 10 additions & 4 deletions components/utils/components-helper.service.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -66,8 +66,14 @@ export class ComponentsHelper {
providers?:ResolvedReflectiveProvider[]):ComponentRef<T> {
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);
}

Expand Down
4 changes: 1 addition & 3 deletions components/utils/utils.class.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -13,7 +11,7 @@ export class Utils {
let view = elem.ownerDocument.defaultView;

if (!view || !view.opener) {
view = Type;
view = (window as any);
}

return view.getComputedStyle(elem);
Expand Down