From ad4fa364d11728be9cd49e99ffcca030a8f2f891 Mon Sep 17 00:00:00 2001 From: Sergey Akopkokhyants Date: Sun, 4 Dec 2016 23:58:46 +0200 Subject: [PATCH] Fixed AOT issue --- .npmignore | 1 + index.ts | 17 ++++++++++------- src/slim-loading-bar.component.ts | 26 ++++++++------------------ src/slim-loading-bar.service.ts | 22 ++++++++-------------- webpack.config.js | 2 -- 5 files changed, 27 insertions(+), 41 deletions(-) diff --git a/.npmignore b/.npmignore index 6cf0619..6b0a540 100644 --- a/.npmignore +++ b/.npmignore @@ -14,6 +14,7 @@ tests coverage !*.metadata.json !bundles/*.js +*.ngFactory.ts ################# ## JetBrains diff --git a/index.ts b/index.ts index c203072..d3342a9 100644 --- a/index.ts +++ b/index.ts @@ -2,23 +2,26 @@ // This project is licensed under the terms of the MIT license. // https://github.com/akserg/ng2-slim-loading-bar -import {NgModule, ModuleWithProviders} from "@angular/core"; +import { NgModule, ModuleWithProviders } from "@angular/core"; -import {SlimLoadingBarComponent} from './src/slim-loading-bar.component'; -import {SlimLoadingBarService} from './src/slim-loading-bar.service'; +import { SlimLoadingBarComponent } from './src/slim-loading-bar.component'; +import { SlimLoadingBarService, slimLoadingBarServiceFactory } from './src/slim-loading-bar.service'; export * from './src/slim-loading-bar.component'; export * from './src/slim-loading-bar.service'; +export let providers = [{ provide: SlimLoadingBarService, useFactory: slimLoadingBarServiceFactory }]; + @NgModule({ - declarations: [SlimLoadingBarComponent], - exports: [SlimLoadingBarComponent] + declarations: [SlimLoadingBarComponent], + exports: [SlimLoadingBarComponent], + providers: providers }) export class SlimLoadingBarModule { - static forRoot(): ModuleWithProviders { + static forRoot(): ModuleWithProviders { return { ngModule: SlimLoadingBarModule, - providers: [SlimLoadingBarService] + providers: providers }; } } diff --git a/src/slim-loading-bar.component.ts b/src/slim-loading-bar.component.ts index e130577..2d80f94 100644 --- a/src/slim-loading-bar.component.ts +++ b/src/slim-loading-bar.component.ts @@ -2,44 +2,34 @@ // This project is licensed under the terms of the MIT license. // https://github.com/akserg/ng2-slim-loading-bar -import {Component, Input, OnInit} from '@angular/core'; +import { Component, Input, OnInit } from '@angular/core'; -import {SlimLoadingBarService, SlimLoadingBarEvent, SlimLoadingBarEventType} from './slim-loading-bar.service'; -import {isPresent} from './slim-loading-bar.utils'; +import { SlimLoadingBarService, SlimLoadingBarEvent, SlimLoadingBarEventType } from './slim-loading-bar.service'; +import { isPresent } from './slim-loading-bar.utils'; /** * A Slim Loading Bar component shows message loading progress bar on the top of web page or parent component. */ @Component({ - moduleId: module.id.toString(), selector: 'ng2-slim-loading-bar', template: `
-
` }) export class SlimLoadingBarComponent implements OnInit { - private _progress: string = '0%'; - @Input() set progress(value: string) { - if (isPresent(value)) { - this._progress = value + '%'; - } - } - get progress(): string { - return this._progress; - } - + @Input() progress: string = '0'; @Input() color: string = 'firebrick'; @Input() height: string = '2px'; @Input() show: boolean = true; - constructor(private service:SlimLoadingBarService) {} + constructor(public service: SlimLoadingBarService) { } ngOnInit(): any { - this.service.observable.subscribe((event:SlimLoadingBarEvent) => { - if (event.type === SlimLoadingBarEventType.PROGRESS) { + this.service.events.subscribe((event: SlimLoadingBarEvent) => { + if (event.type === SlimLoadingBarEventType.PROGRESS && isPresent(event.value)) { this.progress = event.value; } else if (event.type === SlimLoadingBarEventType.COLOR) { this.color = event.value; diff --git a/src/slim-loading-bar.service.ts b/src/slim-loading-bar.service.ts index 78f8f9d..499ca69 100644 --- a/src/slim-loading-bar.service.ts +++ b/src/slim-loading-bar.service.ts @@ -2,10 +2,7 @@ // This project is licensed under the terms of the MIT license. // https://github.com/akserg/ng2-slim-loading-bar -import {Injectable} from '@angular/core'; - -import {Observable} from 'rxjs/Observable'; -import {Subscriber} from 'rxjs/Subscriber'; +import {Injectable, EventEmitter} from '@angular/core'; import {isPresent} from './slim-loading-bar.utils'; @@ -20,6 +17,10 @@ export class SlimLoadingBarEvent { constructor(public type:SlimLoadingBarEventType, public value:any) {} } +export function slimLoadingBarServiceFactory(): SlimLoadingBarService { + return new SlimLoadingBarService(new EventEmitter()); + } + /** * SlimLoadingBar service helps manage Slim Loading bar on the top of screen or parent component */ @@ -34,14 +35,7 @@ export class SlimLoadingBarService { private _intervalCounterId:any = 0; public interval:number = 500; // in milliseconds - public observable: Observable; - private subscriber: Subscriber; - - constructor() { - this.observable = new Observable((subscriber:Subscriber) => { - this.subscriber = subscriber; - }); - } + constructor(public events: EventEmitter) {} set progress(value:number) { if (isPresent(value)) { @@ -92,9 +86,9 @@ export class SlimLoadingBarService { } private emitEvent(event: SlimLoadingBarEvent) { - if (this.subscriber) { + if (this.events) { // Push up a new event - this.subscriber.next(event); + this.events.next(event); } } diff --git a/webpack.config.js b/webpack.config.js index 9f03b51..91578ee 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,8 +13,6 @@ const DefinePlugin = require('webpack/lib/DefinePlugin'); const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin'); module.exports = { - devtool: 'inline-source-map', - resolve: { extensions: ['.ts', '.js'] },