@@ -31,33 +31,101 @@ import {Location} from './src/router/location';
31
31
import { bind , OpaqueToken , Binding } from './core' ;
32
32
import { CONST_EXPR , Type } from './src/core/facade/lang' ;
33
33
34
+ /**
35
+ * Token used to bind the component with the top-level {@link RouteConfig}s for the
36
+ * application.
37
+ *
38
+ * You can use the {@link routerBindings} function in your {@link bootstrap} bindings to
39
+ * simplify setting up these bindings.
40
+ *
41
+ * ## Example ([live demo](http://plnkr.co/edit/iRUP8B5OUbxCWQ3AcIDm))
42
+ *
43
+ * ```
44
+ * import {Component, View} from 'angular2/angular2';
45
+ * import {
46
+ * ROUTER_DIRECTIVES,
47
+ * ROUTER_BINDINGS,
48
+ * ROUTER_PRIMARY_COMPONENT,
49
+ * RouteConfig
50
+ * } from 'angular2/router';
51
+ *
52
+ * @Component ({...})
53
+ * @View ({directives: [ROUTER_DIRECTIVES]})
54
+ * @RouteConfig ([
55
+ * {...},
56
+ * ])
57
+ * class AppCmp {
58
+ * // ...
59
+ * }
60
+ *
61
+ * bootstrap(AppCmp, [
62
+ * ROUTER_BINDINGS,
63
+ * bind(ROUTER_PRIMARY_COMPONENT).toValue(AppCmp)
64
+ * ]);
65
+ * ```
66
+ */
34
67
export const ROUTER_PRIMARY_COMPONENT : OpaqueToken =
35
68
CONST_EXPR ( new OpaqueToken ( 'RouterPrimaryComponent' ) ) ;
36
69
37
- export const ROUTER_DIRECTIVES : any [ ] = CONST_EXPR ( [ RouterOutlet , RouterLink ] ) ;
38
-
39
70
/**
40
- * A list of {@link Binding}. To use the router, you must add this to your application.
71
+ * A list of directives. To use the router directives like {@link RouterOutlet} and
72
+ * {@link RouterLink}, add this to your `directives` array in the {@link View} decorator of your
73
+ * component.
41
74
*
42
- * ## Example
75
+ * ## Example ([live demo](http://plnkr.co/edit/iRUP8B5OUbxCWQ3AcIDm))
76
+ *
77
+ * ```
78
+ * import {Component, View} from 'angular2/angular2';
79
+ * import {ROUTER_DIRECTIVES, routerBindings, RouteConfig} from 'angular2/router';
43
80
*
44
- * ```typescript
45
81
* @Component ({...})
46
82
* @View ({directives: [ROUTER_DIRECTIVES]})
47
83
* @RouteConfig ([
48
- * new Route( ...) ,
84
+ * { ...} ,
49
85
* ])
50
86
* class AppCmp {
51
- * constructor(router: Router, location: Location) {
52
87
* // ...
53
- * }
54
- *
55
88
* }
56
89
*
57
- *
58
90
* bootstrap(AppCmp, [routerBindings(AppCmp)]);
59
91
* ```
60
92
*/
93
+ export const ROUTER_DIRECTIVES : any [ ] = CONST_EXPR ( [ RouterOutlet , RouterLink ] ) ;
94
+
95
+ /**
96
+ * A list of {@link Binding}s. To use the router, you must add this to your application.
97
+ *
98
+ * Note that you also need to bind to {@link ROUTER_PRIMARY_COMPONENT}.
99
+ *
100
+ * You can use the {@link routerBindings} function in your {@link bootstrap} bindings to
101
+ * simplify setting up these bindings.
102
+ *
103
+ * ## Example ([live demo](http://plnkr.co/edit/iRUP8B5OUbxCWQ3AcIDm))
104
+ *
105
+ * ```
106
+ * import {Component, View} from 'angular2/angular2';
107
+ * import {
108
+ * ROUTER_DIRECTIVES,
109
+ * ROUTER_BINDINGS,
110
+ * ROUTER_PRIMARY_COMPONENT,
111
+ * RouteConfig
112
+ * } from 'angular2/router';
113
+ *
114
+ * @Component ({...})
115
+ * @View ({directives: [ROUTER_DIRECTIVES]})
116
+ * @RouteConfig ([
117
+ * {...},
118
+ * ])
119
+ * class AppCmp {
120
+ * // ...
121
+ * }
122
+ *
123
+ * bootstrap(AppCmp, [
124
+ * ROUTER_BINDINGS,
125
+ * bind(ROUTER_PRIMARY_COMPONENT).toValue(AppCmp)
126
+ * ]);
127
+ * ```
128
+ */
61
129
export const ROUTER_BINDINGS : any [ ] = CONST_EXPR ( [
62
130
RouteRegistry ,
63
131
CONST_EXPR ( new Binding ( LocationStrategy , { toClass : PathLocationStrategy } ) ) ,
@@ -74,6 +142,28 @@ function routerFactory(registry, location, primaryComponent) {
74
142
return new RootRouter ( registry , location , primaryComponent ) ;
75
143
}
76
144
145
+ /**
146
+ * A list of {@link Binding}s. To use the router, you must add these bindings to
147
+ * your application.
148
+ *
149
+ * ## Example ([live demo](http://plnkr.co/edit/iRUP8B5OUbxCWQ3AcIDm))
150
+ *
151
+ * ```
152
+ * import {Component, View} from 'angular2/angular2';
153
+ * import {ROUTER_DIRECTIVES, routerBindings, RouteConfig} from 'angular2/router';
154
+ *
155
+ * @Component ({...})
156
+ * @View ({directives: [ROUTER_DIRECTIVES]})
157
+ * @RouteConfig ([
158
+ * {...},
159
+ * ])
160
+ * class AppCmp {
161
+ * // ...
162
+ * }
163
+ *
164
+ * bootstrap(AppCmp, [routerBindings(AppCmp)]);
165
+ * ```
166
+ */
77
167
export function routerBindings ( primaryComponent : Type ) : Array < any > {
78
168
return [ ROUTER_BINDINGS , bind ( ROUTER_PRIMARY_COMPONENT ) . toValue ( primaryComponent ) ] ;
79
169
}
0 commit comments