63
63
</doc:example>
64
64
*/
65
65
function $RouteProvider ( ) {
66
+ var routes = { } ;
67
+
68
+ /**
69
+ * @ngdoc method
70
+ * @name angular.module.ng.$route#when
71
+ * @methodOf angular.module.ng.$route
72
+ *
73
+ * @param {string } path Route path (matched against `$location.hash`)
74
+ * @param {Object } route Mapping information to be assigned to `$route.current` on route
75
+ * match.
76
+ *
77
+ * Object properties:
78
+ *
79
+ * - `controller` – `{function()=}` – Controller fn that should be associated with newly
80
+ * created scope.
81
+ * - `template` – `{string=}` – path to an html template that should be used by
82
+ * {@link angular.module.ng.$compileProvider.directive.ng:view ng:view} or
83
+ * {@link angular.module.ng.$compileProvider.directive.ng:include ng:include} widgets.
84
+ * - `redirectTo` – {(string|function())=} – value to update
85
+ * {@link angular.module.ng.$location $location} path with and trigger route redirection.
86
+ *
87
+ * If `redirectTo` is a function, it will be called with the following parameters:
88
+ *
89
+ * - `{Object.<string>}` - route parameters extracted from the current
90
+ * `$location.path()` by applying the current route template.
91
+ * - `{string}` - current `$location.path()`
92
+ * - `{Object}` - current `$location.search()`
93
+ *
94
+ * The custom `redirectTo` function is expected to return a string which will be used
95
+ * to update `$location.path()` and `$location.search()`.
96
+ *
97
+ * - `[reloadOnSearch=true]` - {boolean=} - reload route when only $location.search()
98
+ * changes.
99
+ *
100
+ * If the option is set to false and url in the browser changes, then
101
+ * $routeUpdate event is emited on the current route scope. You can use this event to
102
+ * react to {@link angular.module.ng.$routeParams} changes:
103
+ *
104
+ * function MyCtrl($route, $routeParams) {
105
+ * this.$on('$routeUpdate', function() {
106
+ * // do stuff with $routeParams
107
+ * });
108
+ * }
109
+ *
110
+ * @returns {Object } route object
111
+ *
112
+ * @description
113
+ * Adds a new route definition to the `$route` service.
114
+ */
115
+ this . when = function ( path , route ) {
116
+ var routeDef = routes [ path ] ;
117
+ if ( ! routeDef ) routeDef = routes [ path ] = { reloadOnSearch : true } ;
118
+ if ( route ) extend ( routeDef , route ) ; // TODO(im): what the heck? merge two route definitions?
119
+ return routeDef ;
120
+ } ;
121
+
122
+ /**
123
+ * @ngdoc method
124
+ * @name angular.module.ng.$route#otherwise
125
+ * @methodOf angular.module.ng.$route
126
+ *
127
+ * @description
128
+ * Sets route definition that will be used on route change when no other route definition
129
+ * is matched.
130
+ *
131
+ * @param {Object } params Mapping information to be assigned to `$route.current`.
132
+ */
133
+ this . otherwise = function ( params ) {
134
+ this . when ( null , params ) ;
135
+ } ;
136
+
137
+
66
138
this . $get = [ '$rootScope' , '$location' , '$routeParams' , '$controller' ,
67
139
function ( $rootScope , $location , $routeParams , $controller ) {
68
140
/**
@@ -112,8 +184,7 @@ function $RouteProvider(){
112
184
* instance of the Controller.
113
185
*/
114
186
115
- var routes = { } ,
116
- matcher = switchRouteMatcher ,
187
+ var matcher = switchRouteMatcher ,
117
188
parentScope = $rootScope ,
118
189
dirty = 0 ,
119
190
forceReload = false ,
@@ -136,76 +207,6 @@ function $RouteProvider(){
136
207
if ( scope ) parentScope = scope ;
137
208
} ,
138
209
139
- /**
140
- * @ngdoc method
141
- * @name angular.module.ng.$route#when
142
- * @methodOf angular.module.ng.$route
143
- *
144
- * @param {string } path Route path (matched against `$location.hash`)
145
- * @param {Object } route Mapping information to be assigned to `$route.current` on route
146
- * match.
147
- *
148
- * Object properties:
149
- *
150
- * - `controller` – `{function()=}` – Controller fn that should be associated with newly
151
- * created scope.
152
- * - `template` – `{string=}` – path to an html template that should be used by
153
- * {@link angular.module.ng.$compileProvider.directive.ng:view ng:view} or
154
- * {@link angular.module.ng.$compileProvider.directive.ng:include ng:include} widgets.
155
- * - `redirectTo` – {(string|function())=} – value to update
156
- * {@link angular.module.ng.$location $location} path with and trigger route redirection.
157
- *
158
- * If `redirectTo` is a function, it will be called with the following parameters:
159
- *
160
- * - `{Object.<string>}` - route parameters extracted from the current
161
- * `$location.path()` by applying the current route template.
162
- * - `{string}` - current `$location.path()`
163
- * - `{Object}` - current `$location.search()`
164
- *
165
- * The custom `redirectTo` function is expected to return a string which will be used
166
- * to update `$location.path()` and `$location.search()`.
167
- *
168
- * - `[reloadOnSearch=true]` - {boolean=} - reload route when only $location.search()
169
- * changes.
170
- *
171
- * If the option is set to false and url in the browser changes, then
172
- * $routeUpdate event is emited on the current route scope. You can use this event to
173
- * react to {@link angular.module.ng.$routeParams} changes:
174
- *
175
- * function MyCtrl($route, $routeParams) {
176
- * this.$on('$routeUpdate', function() {
177
- * // do stuff with $routeParams
178
- * });
179
- * }
180
- *
181
- * @returns {Object } route object
182
- *
183
- * @description
184
- * Adds a new route definition to the `$route` service.
185
- */
186
- when : function ( path , route ) {
187
- var routeDef = routes [ path ] ;
188
- if ( ! routeDef ) routeDef = routes [ path ] = { reloadOnSearch : true } ;
189
- if ( route ) extend ( routeDef , route ) ; // TODO(im): what the heck? merge two route definitions?
190
- dirty ++ ;
191
- return routeDef ;
192
- } ,
193
-
194
- /**
195
- * @ngdoc method
196
- * @name angular.module.ng.$route#otherwise
197
- * @methodOf angular.module.ng.$route
198
- *
199
- * @description
200
- * Sets route definition that will be used on route change when no other route definition
201
- * is matched.
202
- *
203
- * @param {Object } params Mapping information to be assigned to `$route.current`.
204
- */
205
- otherwise : function ( params ) {
206
- $route . when ( null , params ) ;
207
- } ,
208
-
209
210
/**
210
211
* @ngdoc method
211
212
* @name angular.module.ng.$route#reload
0 commit comments