You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-1Lines changed: 38 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1290,7 +1290,7 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
1290
1290
### Route Resolve Promises
1291
1291
###### [Style [Y081](#style-y081)]
1292
1292
1293
-
- When a controller depends on a promise to be resolved, resolve those dependencies in the `$routeProvider` before the controller logic is executed. If you need to conditionally cancel a route before the controller is activated, use a route resolver.
1293
+
- When a controller depends on a promise to be resolved before the controller is activated, resolve those dependencies in the `$routeProvider` before the controller logic is executed. If you need to conditionally cancel a route before the controller is activated, use a route resolver.
1294
1294
1295
1295
*Why?*: A controller may require data before it loads. That data may come from a promise via a custom factory or [$http](https://docs.angularjs.org/api/ng/service/$http). Using a [route resolve](https://docs.angularjs.org/api/ngRoute/provider/$routeProvider) allows the promise to resolve before the controller logic executes, so it might take action based on that data from the promise.
1296
1296
@@ -1345,6 +1345,43 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
1345
1345
}
1346
1346
```
1347
1347
1348
+
Note: The example below shows the route resolve points to a named function, which is easier to debug and easier to handle dependency injection.
1349
+
1350
+
```javascript
1351
+
/* even better */
1352
+
1353
+
// route-config.js
1354
+
angular
1355
+
.module('app')
1356
+
.config(config);
1357
+
1358
+
functionconfig($routeProvider) {
1359
+
$routeProvider
1360
+
.when('/avengers', {
1361
+
templateUrl:'avengers.html',
1362
+
controller:'Avengers',
1363
+
controllerAs:'vm',
1364
+
resolve: {
1365
+
moviesPrepService: moviesPrepService
1366
+
}
1367
+
});
1368
+
}
1369
+
1370
+
function(movieService) {
1371
+
returnmovieService.getMovies();
1372
+
}
1373
+
1374
+
// avengers.js
1375
+
angular
1376
+
.module('app')
1377
+
.controller('Avengers', Avengers);
1378
+
1379
+
Avengers.$inject= ['moviesPrepService'];
1380
+
functionAvengers(moviesPrepService) {
1381
+
var vm =this;
1382
+
vm.movies=moviesPrepService.movies;
1383
+
}
1384
+
```
1348
1385
Note: The code example's dependency on `movieService` is not minification safe on its own. For details on how to make this code minification safe, see the sections on [dependency injection](#manual-annotating-for-dependency-injection) and on [minification and annotation](#minification-and-annotation).
0 commit comments