-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(defaults): defaults are now configured by passing them via Confi…
…rmModule.forRoot() BREAKING CHANGE: Before: ``` const defaults = new ConfirmOptions(); defaults.confirmButtonType = 'danger'; providers: [ {provide: ConfirmOptions, useValue: defaults} ] ``` After: ``` imports: [ ConfirmModule.forRoot({ confirmButtonType: 'danger' }) ] ```
- Loading branch information
Matt Lewis
committed
Nov 7, 2016
1 parent
c486999
commit 802c1ef
Showing
8 changed files
with
95 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,40 @@ | ||
import {NgModule} from '@angular/core'; | ||
import {NgModule, ModuleWithProviders, OpaqueToken} from '@angular/core'; | ||
import {CommonModule} from '@angular/common'; | ||
import {Confirm} from './confirm.directive'; | ||
import {ConfirmPopover} from './confirmPopover.component'; | ||
import {Focus} from './focus.directive'; | ||
import {ConfirmOptions, ConfirmOptionsInterface} from './confirmOptions.provider'; | ||
|
||
const USER_OPTIONS: OpaqueToken = new OpaqueToken('confirmation popover user options'); | ||
|
||
export function optionsFactory(userOptions: ConfirmOptions): ConfirmOptions { | ||
const options: ConfirmOptions = new ConfirmOptions(); | ||
Object.assign(options, userOptions); | ||
return options; | ||
} | ||
|
||
@NgModule({ | ||
declarations: [Confirm, ConfirmPopover, Focus], | ||
imports: [CommonModule], | ||
exports: [Confirm, Focus], | ||
entryComponents: [ConfirmPopover] | ||
}) | ||
export class ConfirmModule {} | ||
export class ConfirmModule { | ||
|
||
static forRoot(options?: ConfirmOptionsInterface): ModuleWithProviders { | ||
|
||
return { | ||
ngModule: ConfirmModule, | ||
providers: [{ | ||
provide: USER_OPTIONS, | ||
useValue: options | ||
}, { | ||
provide: ConfirmOptions, | ||
useFactory: optionsFactory, | ||
deps: [USER_OPTIONS] | ||
}] | ||
}; | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export {ConfirmOptions} from './confirmOptions.provider'; | ||
export * from './confirm.module'; | ||
export {ConfirmModule} from './confirm.module'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters