|
14 | 14 | import {IQService} from "angular";
|
15 | 15 | import {Router} from "../router";
|
16 | 16 | import {services} from "../common/coreservices";
|
17 |
| -import {isObject} from "../common/common"; |
| 17 | +import {forEach, isObject} from "../common/common"; |
| 18 | +import {RawParams} from "../params/interface"; |
| 19 | +import {Node} from "../path/module"; |
| 20 | +import {Resolvables} from "../resolve/interface"; |
| 21 | +import {Resolvable, ResolveContext} from "../resolve/module"; |
| 22 | +import {State} from "../state/module"; |
18 | 23 |
|
19 | 24 | let app = angular.module("ui.router.angular1", []);
|
20 | 25 |
|
@@ -80,21 +85,40 @@ function ng1UIRouter($locationProvider) {
|
80 | 85 | };
|
81 | 86 |
|
82 | 87 | bindFunctions(["replace", "url", "path", "search", "hash"], $location, services.location);
|
83 |
| - bindFunctions([ 'port', 'protocol', 'host'], $location, services.locationConfig); |
| 88 | + bindFunctions(['port', 'protocol', 'host'], $location, services.locationConfig); |
84 | 89 | bindFunctions(['baseHref'], $browser, services.locationConfig);
|
85 | 90 |
|
86 | 91 | return router;
|
87 | 92 | }
|
88 | 93 | }
|
89 | 94 |
|
| 95 | +function resolveFactory() { |
| 96 | + return { |
| 97 | + resolve: (invocables, locals, parent, self) => { |
| 98 | + let state = new State({ params: {} }); |
| 99 | + let node = new Node(state, <RawParams> {}); |
| 100 | + let context = new ResolveContext([node]); |
| 101 | + let resolvables: Resolvables = {}; |
| 102 | + forEach(invocables, (invocable, key) => { |
| 103 | + resolvables[key] = new Resolvable(`${key}`, invocable); |
| 104 | + }); |
| 105 | + |
| 106 | + context.addResolvables(resolvables, node.state); |
| 107 | + |
| 108 | + return context.resolvePath(); |
| 109 | + } |
| 110 | + }; |
| 111 | +} |
| 112 | + |
90 | 113 | angular.module('ui.router.init', []).provider("ng1UIRouter", <any> ng1UIRouter);
|
91 | 114 | // Register as a provider so it's available to other providers
|
92 | 115 | angular.module('ui.router.util').provider('$urlMatcherFactory', ['ng1UIRouterProvider', () => router.urlMatcherFactory]);
|
93 | 116 | angular.module('ui.router.router').provider('$urlRouter', ['ng1UIRouterProvider', () => router.urlRouterProvider]);
|
94 | 117 | angular.module('ui.router.state').provider('$state', ['ng1UIRouterProvider', () => router.stateProvider]);
|
| 118 | +angular.module('ui.router.resolve', []).factory('$resolve', <any> resolveFactory); |
95 | 119 |
|
96 | 120 | /* This effectively calls $get() to init when we enter runtime */
|
97 | 121 | angular.module('ui.router.init').run(['ng1UIRouter', function(ng1UIRouter) { }]);
|
| 122 | +angular.module('ui.router.resolve').run(['$resolve', function(resolve) { }]); |
98 | 123 | angular.module('ui.router.state').run(['$state', function($state) { }]);
|
99 | 124 | angular.module('ui.router.util').run(['$urlMatcherFactory', function($urlMatcherFactory) { }]);
|
100 |
| - |
|
0 commit comments