|
99 | 99 | };
|
100 | 100 | }]);
|
101 | 101 |
|
| 102 | + // rewrite $routeProvider.when |
| 103 | + if (app.requires && app.requires.indexOf('ngRoute') !== -1) { |
| 104 | + app.config(['$routeProvider', function ($routeProvider) { |
| 105 | + var whenFn = $routeProvider.when; |
| 106 | + $routeProvider.when = function(path, config) { |
| 107 | + return whenFn.call($routeProvider, path, app.route(config)); |
| 108 | + }; |
| 109 | + }]); |
| 110 | + } |
| 111 | + // rewrite $stateProvider.state |
| 112 | + if (app.requires && app.requires.indexOf('ui.router') !== -1) { |
| 113 | + app.config(['$stateProvider', function ($stateProvider) { |
| 114 | + var stateFn = $stateProvider.state; |
| 115 | + $stateProvider.state = function(state, config) { |
| 116 | + return stateFn.call($stateProvider, state, app.route(config)); |
| 117 | + }; |
| 118 | + }]); |
| 119 | + } |
102 | 120 |
|
103 | 121 | /**
|
104 |
| - * Generate $routeProvider.route or $stateProvider.state. |
| 122 | + * Rewrite config for $routeProvider.when or $stateProvider.state. |
105 | 123 | *
|
106 | 124 | * Populate the resolve attribute using either 'controllerUrl'.
|
107 | 125 | *
|
108 |
| - * @param config {Object} |
| 126 | + * @param {Object} config |
109 | 127 | * @returns the modified config
|
110 | 128 | */
|
111 | 129 | app.route = function (config) {
|
112 |
| - var controllerUrl = config.controllerUrl; |
113 |
| - if (controllerUrl !== undefined) { |
114 |
| - delete config.controllerUrl; |
| 130 | + function rewriteViewConfig(config) { |
| 131 | + if (config.hasOwnProperty('controllerUrl')) { |
| 132 | + var controllerUrl = config.controllerUrl; |
| 133 | + delete config.controllerUrl; |
| 134 | + |
| 135 | + var resolve = config.resolve || {}; |
| 136 | + resolve.dummyController = app.load([controllerUrl]); |
| 137 | + config.resolve = resolve; |
| 138 | + } |
| 139 | + } |
115 | 140 |
|
116 |
| - var resolve = config.resolve || {}; |
117 |
| - resolve.dummyController = app.load(controllerUrl); |
118 |
| - config.resolve = resolve; |
| 141 | + // multiple views support |
| 142 | + if (config.hasOwnProperty('views')) { |
| 143 | + Object.keys(config.views).forEach(function(view) { |
| 144 | + rewriteViewConfig(config.views[view]); |
| 145 | + }); |
| 146 | + } else { |
| 147 | + rewriteViewConfig(config); |
119 | 148 | }
|
120 | 149 |
|
121 | 150 | return config;
|
|
126 | 155 | * Load external resources, such as Controller, Service, etc.
|
127 | 156 | *
|
128 | 157 | * @param {String|Array} dependencies
|
129 |
| - * @returns {*} |
| 158 | + * @returns {*} a promised function to ajax load resource |
130 | 159 | */
|
131 | 160 | app.load = function (dependencies) {
|
132 | 161 | if (!angular.isArray(dependencies)) {
|
|
148 | 177 | var injector;
|
149 | 178 |
|
150 | 179 | /**
|
151 |
| - * Get angular injector object by name. |
| 180 | + * Get angular injector object by name in module scope. |
152 | 181 | *
|
153 | 182 | * @param {String} name
|
154 |
| - * @returns {*} |
| 183 | + * @returns {*} the injected object |
155 | 184 | */
|
156 | 185 | app.get = function (name) {
|
157 | 186 | if (injector === undefined) {
|
|
0 commit comments