Skip to content

Commit

Permalink
feat(config): Pass the module object to the module config function
Browse files Browse the repository at this point in the history
```
export function routerConfig(router: UIRouter, injector: Injector, module: StatesModule) {

}

...
@UIRouterModule.forRoot({ states: STATES, config: routerConfig });
...
```

Closes #55
  • Loading branch information
christopherthielen committed Mar 5, 2017
1 parent c894fbc commit e9705b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/uiRouterConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import {StatesModule, RootModule} from "./uiRouterNgModule";
import {Injector} from "@angular/core";
import {isDefined} from "ui-router-core";

export function applyModuleConfig(uiRouter: UIRouter, injector: Injector, options: StatesModule = {}): StateObject[] {
if (isFunction(options.config)) {
options.config(uiRouter, injector, options);
export function applyModuleConfig(uiRouter: UIRouter, injector: Injector, module: StatesModule = {}): StateObject[] {
if (isFunction(module.config)) {
module.config(uiRouter, injector, module);
}

let states = options.states || [];
let states = module.states || [];
return states.map(state => uiRouter.stateRegistry.register(state));
}

export function applyRootModuleConfig(uiRouter: UIRouter, injector: Injector, config: RootModule) {
isDefined(config.deferIntercept) && uiRouter.urlService.deferIntercept(config.deferIntercept);
isDefined(config.otherwise) && uiRouter.urlService.rules.otherwise(config.otherwise);
export function applyRootModuleConfig(uiRouter: UIRouter, injector: Injector, module: RootModule) {
isDefined(module.deferIntercept) && uiRouter.urlService.deferIntercept(module.deferIntercept);
isDefined(module.otherwise) && uiRouter.urlService.rules.otherwise(module.otherwise);
}


7 changes: 4 additions & 3 deletions src/uiRouterNgModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ export interface StatesModule {
*
* If a UI-Router Module needs to perform some configuration (such as registering
* parameter types or Transition Hooks) a `configFn` should be supplied.
* The function will be passed the `UIRouter` instance and the module's `Injector`
* The function will be passed the `UIRouter` instance, the module's `Injector`,
* and the module object.
*
* #### Example:
* ```js
Expand All @@ -200,7 +201,7 @@ export interface StatesModule {
* import { requireAuthHook } from "./requireAuthHook";
* import { MyService } from "./myService";
*
* export function configureMyModule(uiRouter: UIRouter, injector: Injector, options: StatesModule) {
* export function configureMyModule(uiRouter: UIRouter, injector: Injector, module: StatesModule) {
* // Get UIRouter services off the UIRouter object
* let urlConfig = uiRouter.urlService.config;
* let transitionService = uiRouter.transitionService;
Expand Down Expand Up @@ -228,6 +229,6 @@ export interface StatesModule {
* class MyModule {}
* ```
*/
config?: (uiRouterInstance: UIRouter, injector: Injector, options: StatesModule) => any;
config?: (uiRouterInstance: UIRouter, injector: Injector, module: StatesModule) => any;
}

0 comments on commit e9705b0

Please sign in to comment.