Skip to content

Commit

Permalink
Fixed AOT issue
Browse files Browse the repository at this point in the history
  • Loading branch information
akserg committed Dec 4, 2016
1 parent d4faa14 commit ad4fa36
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 41 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tests
coverage
!*.metadata.json
!bundles/*.js
*.ngFactory.ts

#################
## JetBrains
Expand Down
17 changes: 10 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
}
26 changes: 8 additions & 18 deletions src/slim-loading-bar.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
<div class="slim-loading-bar">
<div class="slim-loading-bar-progress" [style.width]="progress" [style.backgroundColor]="color" [style.color]="color"
<div class="slim-loading-bar-progress" [style.width]="progress + '%'" [style.backgroundColor]="color" [style.color]="color"
[style.height]="height" [style.opacity]="show ? '1' : '0'"></div>
</div>`
})
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;
Expand Down
22 changes: 8 additions & 14 deletions src/slim-loading-bar.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -20,6 +17,10 @@ export class SlimLoadingBarEvent {
constructor(public type:SlimLoadingBarEventType, public value:any) {}
}

export function slimLoadingBarServiceFactory(): SlimLoadingBarService {
return new SlimLoadingBarService(new EventEmitter<SlimLoadingBarEvent>());
}

/**
* SlimLoadingBar service helps manage Slim Loading bar on the top of screen or parent component
*/
Expand All @@ -34,14 +35,7 @@ export class SlimLoadingBarService {
private _intervalCounterId:any = 0;
public interval:number = 500; // in milliseconds

public observable: Observable<SlimLoadingBarEvent>;
private subscriber: Subscriber<SlimLoadingBarEvent>;

constructor() {
this.observable = new Observable<SlimLoadingBarEvent>((subscriber:Subscriber<SlimLoadingBarEvent>) => {
this.subscriber = subscriber;
});
}
constructor(public events: EventEmitter<SlimLoadingBarEvent>) {}

set progress(value:number) {
if (isPresent(value)) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 0 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
},
Expand Down

0 comments on commit ad4fa36

Please sign in to comment.