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
Although UI-Router has always allowed views to be defined as arbitrary `template` and `controller` combinations, we
@@ -17,66 +17,364 @@ highly recommend that the Angular 1.5 component model is adopted instead.
17
17
In this guide, we'll cover how to route to Angular 1.5 components and how to supply them with resolve data.
18
18
19
19
20
-
# Angular 1.5 .`component()`
20
+
# Angular 1.5 `.component()`
21
21
22
22
An Angular 1.5 component is a reusable piece of a web page, which encapsulates both markup and behavior.
23
23
A component is self-contained; it does not access `$scope` values from parent elements, nor does it provide values on `$scope` for children to access.
24
24
A component gets all its input data from a parent component as explicit property bindings via attributes in the parent's template.
25
-
Any outputs (for communication to the parent) is done using event callbacks, also via attributes in the parent template.
25
+
Any outputs (for communication to the parent) are provided as event callbacks, likewise as attributes in the parent template.
26
26
27
27
In addition to inputs and output bindings, a component also has lifecycle hooks.
28
28
29
29
The component model from Angular 1.5 aligns closely with the component model from Angular 2.
30
-
From a high level, it even has much in common with even React's or Web Component's models.
31
-
This level of parity between frameworks allows you to reason about application structure in a similar way, no matter what framework you are using.
30
+
From a high level, it even has much in common with even React or Web Component models.
31
+
This parity between frameworks allows you to reason about application structure in a similar way, no matter which framework you are using.
32
32
{: .notice--info}
33
33
34
34
To learn more about Angular 1.5 components, refer to the [official docs](https://docs.angularjs.org/guide/component)
35
35
and read a [blog or two](https://www.google.com/search?q=angular+1.5+component+blog&oq=angular+1.5+component+blog).
36
36
37
37
# UI-Router Legacy
38
38
39
-
UI-Router applications are defined as a tree of states.
40
-
Each state typically has one or more views.
41
-
42
-
In legacy UI-Router, the only way to define a view was to provide a `template` and a `controller`.
43
-
The `template` provided the DOM layout, while the `controller` injected services and resolve data, and implemented logic required to make the view work.
39
+
In legacy UI-Router, the only way to define a state's view is to using a `template` and a `controller`.
40
+
The `template` defines the DOM layout, while the `controller` injects resolve data and services,
41
+
and implements logic required to make the view work.
44
42
45
43
A typical legacy (non-component) state definition might look like this:
46
44
47
45
```js
48
46
.state('fooState', {
49
47
url:'/foo/:fooId',
48
+
template:'/partials/foo.html',
49
+
controller:'FooController',
50
50
resolve: {
51
-
fooValue:function($stateParams, $http) {
52
-
return$http.get('/api/foo/'+$stateParams.fooId)
53
-
.then(function(resp) { returnresp.data; });
51
+
fooData:function(FooService, $stateParams) {
52
+
returnFooService.getFoo($stateParams.fooId)
54
53
}
55
-
},
56
-
template:'/partials/foo.html',
57
-
controller:'FooController'
54
+
}
58
55
});
59
56
```
60
57
61
-
Where `fooController.js` is:
58
+
In `fooController.js`, the resolved `fooData` is injected and placed onto the `$scope` for the template to use.
59
+
Additional services are also injected to wire up desired behavior in the view.
0 commit comments