Skip to content

Commit c7b23b1

Browse files
committed
added more details to the route resolver and controller activate techniques
1 parent 8b0fe57 commit c7b23b1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,9 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
12331233
12341234
*Why?*: Placing start-up logic in a consistent place in the controller makes it easier to locate, more consistent to test, and helps avoid spreading out the activation logic across the controller.
12351235
1236-
Note: If you need to conditionally cancel the route before you start use the controller, use a route resolve instead.
1236+
*Why?: The controller `activate` makes it convenient to re-use the logic for a refresh for the controller/View, keeps the logic together, gets the user to the View faster, makes animations easy on the `ng-view` or `ui-view`, and feels snappier to the user.
1237+
1238+
Note: If you need to conditionally cancel the route before you start use the controller, use a [route resolve](#style-y081) instead.
12371239
12381240
```javascript
12391241
/* avoid */
@@ -1274,8 +1276,14 @@ While this guide explains the *what*, *why* and *how*, I find it helpful to see
12741276
12751277
- 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.
12761278
1279+
- Use a route resolve when you want to decide to cancel the route before ever transitioning to the View.
1280+
12771281
*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.
12781282
1283+
*Why?: The code executes after the route and in the controller’s activate function. The View starts to load right away. Data binding kicks in when the activate promise resolves. A “busy” animation can be shown during the view transition (via ng-view or ui-view)
1284+
1285+
Note: The code executes before the route via a promise. Rejecting the promise cancels the route. Resolve makes the new view wait for the route to resolve. A “busy” animation can be shown before the resolve and through the view transition. If you want to get to the View faster and do not require a checkpoint to decide if you can get to the View, consider the [controller `activate` technique](#style-y080) instead.
1286+
12791287
```javascript
12801288
/* avoid */
12811289
angular

0 commit comments

Comments
 (0)