Skip to content

Commit

Permalink
fixed module forRoot for optional provider parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
arielfaur committed Jun 9, 2017
1 parent 079ca52 commit b9c7f6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions demo/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export function myCustomAudioProviderFactory() {
}

export function providers() {
return [{provide: ErrorHandler, useClass: IonicErrorHandler}, SplashScreen, StatusBar];
return [
{provide: ErrorHandler, useClass: IonicErrorHandler},
SplashScreen,
StatusBar
];
}
export function entryComponents() {
return pages;
Expand All @@ -41,7 +45,7 @@ export function declarations() {
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
IonicAudioModule.forRoot({ provide: AudioProvider, useFactory: myCustomAudioProviderFactory }),
IonicAudioModule.forRoot(),
// or use custom function above to force a specific provider
// { provide: AudioProvider, useFactory: myCustomAudioProviderFactory }
],
Expand Down
14 changes: 11 additions & 3 deletions src/ionic-audio.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {AudioTrackComponent} from './ionic-audio-track-component';
import {AudioTrackProgressComponent, AudioTrackProgressBarComponent} from './ionic-audio-track-progress-component';
import {AudioTrackPlayComponent} from './ionic-audio-track-play-component';
import {AudioTimePipe} from './ionic-audio-time-pipe';
import {AudioProvider, CordovaMediaProvider, WebAudioProvider} from './ionic-audio-providers';
import {AudioProvider, audioProviderFactory} from './ionic-audio-providers';

export function declarations() {
return [
Expand All @@ -15,7 +15,15 @@ export function declarations() {
AudioTrackProgressBarComponent,
AudioTrackPlayComponent,
AudioTimePipe
]
];
}

export function providers(audioProvider?: any) {
audioProvider = audioProvider || { provide: AudioProvider, useFactory: audioProviderFactory }

return [
audioProvider
];
}

@NgModule({
Expand All @@ -33,7 +41,7 @@ export class IonicAudioModule {
static forRoot(audioProvider?: any): ModuleWithProviders {
return {
ngModule: IonicAudioModule,
providers: audioProvider
providers: providers(audioProvider)
};
}
}

0 comments on commit b9c7f6d

Please sign in to comment.