@@ -170,7 +170,7 @@ a(id="class-metadata")
170
170
Each item in the array corresponds to a decorator.
171
171
172
172
The pattern of creating a constructor and decorating it with metadata is so common that Angular
173
- provides an alternative convenience Class API for it for ES5 Javascript.
173
+ provides an alternative ES5 convenience class API for it for ES5 Javascript.
174
174
This API lets us define everything in a single expression.
175
175
176
176
With this API we first call the `ng.core.Component` function, followed by a chained `Class`
@@ -264,102 +264,99 @@ a(id="property-metadata")
264
264
:marked
265
265
## Dependency Injection
266
266
267
- - var top= " vertical-align:top"
268
- table( width ="100%" )
269
- col( width ="50%" )
270
- col( width ="50%" )
271
- tr
272
- th TypeScript
273
- th ES5 JavaScript
274
- tr( style =top)
275
- td
276
- :marked
277
- ### Injection by Type
267
+ ### Injection by Type
278
268
279
- Angular can often use TypeScript type information to
280
- determine what needs to be injected.
281
-
282
- + makeExample('cb-ts-to-js/ts/app/hero-di.component.ts' )( format ="." )
283
-
284
- td
285
- :marked
286
- ### Injection with Parameter Tokens
287
-
288
- Since no type information is available in ES5 JavaScript,
289
- we must identify "injectables" in some other way.
290
-
291
- We attach a `parameters` array to the constructor function.
292
- Each array item is the dependency injection token that identifies the thing to be injected.
293
- Often the token is the constructor function for the class-like dependency.
294
-
295
- + makeExample('cb-ts-to-js/js/app/hero-di.component.js' )( format ="." )
296
-
297
- :marked
298
- When using the class convenience API, we can also supply the parameter
299
- tokens by wrapping the constructor in an array.
269
+ Angular can often use TypeScript type information to determine what needs to be injected.
270
+ ES6 with decorators can also make use of type information.
300
271
301
- + makeExample('cb-ts-to-js/js/app/hero-di-inline.component.js' )( format ="." )
272
+ Since no type information is available in ES5/6 JavaScript, we must identify "injectables" in
273
+ some other way.
302
274
303
- tr( style =top)
304
- td
305
- :marked
306
- ### Injection with the @Inject decorator
307
-
308
- When the thing being injected doesn't correspond directly to a type,
309
- we use the `@Inject()` decorator to supply the injection token.
310
-
311
- In this example, we're injecting a string identified by the "heroName" token.
312
-
313
- + makeExample('cb-ts-to-js/ts/app/hero-di-inject.component.ts' )( format ="." )
314
-
315
- td
316
- :marked
317
- ### Injection with plain string tokens
318
-
319
- In JavaScript we add the token string to the injection parameters array.
275
+ We attach a `parameters` array to the constructor function.
276
+ Each array item is the dependency injection token that identifies the thing to be injected.
277
+ Often the token is the constructor function for the class-like dependency.
278
+
279
+ In ES6 the decorators need to be inside a nested array.
280
+ When using the ES5 class convenience API, we can also supply the parameter tokens by wrapping
281
+ the constructor in an array.
320
282
321
- + makeExample('cb-ts-to-js/js/app/hero-di-inject.component.js' ,'parameters' )( format ="." )
322
-
323
- :marked
324
- Alternatively, we can create a token with the `Inject` method and
325
- add that to the constructor array in the annotations like this:
326
-
327
- + makeExample('cb-ts-to-js/js/app/hero-di-inject.component.js' ,'ctor' )( format ="." )
283
+ + makeTabs(`
284
+ cb-ts-to-js/ts/app/hero-di.component.ts,
285
+ cb-ts-to-js/js-es6-decorators/app/hero-di.component.es6,
286
+ cb-ts-to-js/js-es6/app/hero-di.component.es6,
287
+ cb-ts-to-js/js/app/hero-di.component.js,
288
+ cb-ts-to-js/js/app/hero-di-inline.component.js
289
+ ` ,`
290
+ ` ,`
291
+ Typescript,
292
+ ES6 Javascript with decorators,
293
+ ES6 Javascript,
294
+ ES5 Javascript,
295
+ ES5 Javascript with Class API
296
+ ` )
328
297
329
- tr( style =top)
330
- td
331
- :marked
332
- ### Additional Injection Decorators
298
+ :marked
299
+ ### Injection with the @Inject decorator
333
300
334
- We can attach additional decorators to constructor parameters
335
- to qualify the injection behavior. We can mark
336
- optional dependencies with the [`@Optional`](../api/core/index/Optional-decorator.html),
337
- inject host element attributes with [`@Attribute`](../api/core/index/Attribute-interface.html),
338
- inject content child queries with [`@ContentChild`](../api/core/index/ContentChild-decorator.html)
339
- and inject view child queries with [`@ViewChild`](../api/core/index/ViewChild-decorator.html)).
301
+ When the thing being injected doesn't correspond directly to a type, we use the
302
+ `@Inject()` decorator to supply the injection token.
303
+ In this example, we're injecting a string identified by the "heroName" token.
340
304
341
- + makeExample('cb-ts-to-js/ts/app/hero-di-inject-additional.component.ts' )( format ="." )
305
+ In ES5/6 JavaScript we add the token string to the injection parameters array.
306
+ Alternatively, when using the ES5 convenience class API we can create a token with the
307
+ `Inject` method and add that to the constructor array in the annotations.
342
308
343
- td
344
- :marked
345
- ### Additional Injection Metadata with Nested Arrays
309
+ + makeTabs(`
310
+ cb-ts-to-js/ts/app/hero-di-inject.component.ts,
311
+ cb-ts-to-js/js-es6-decorators/app/hero-di-inject.component.es6,
312
+ cb-ts-to-js/js-es6/app/hero-di-inject.component.es6,
313
+ cb-ts-to-js/js/app/hero-di-inject.component.js,
314
+ cb-ts-to-js/js/app/hero-di-inject.component.js
315
+ ` ,`
316
+ ,
317
+ ,
318
+ ,
319
+ parameters,
320
+ ctor
321
+ ` ,`
322
+ Typescript,
323
+ ES6 Javascript with decorators,
324
+ ES6 Javascript,
325
+ ES5 Javascript,
326
+ ES5 Javascript with Class API
327
+ ` )
346
328
347
- To achieve the same effect in JavaScript, use the constructor array notation
348
- in which the injection information precedes the constructor function itself.
349
-
350
- Use the injection support functions `Attribute`, `Host`, `Optional`, `Self`, `SkipSelf` to qualify dependency injection behavior.
351
-
352
- Use a nested array to combine injection functions.
329
+ :marked
330
+ ### Additional Injection Decorators
353
331
354
- + makeExample('cb-ts-to-js/js/app/hero-di-inject-additional.component.js' )( format ="." )
332
+ We can attach additional decorators to constructor parameters to qualify the injection behavior.
333
+ We can mark optional dependencies with the [`@Optional`](../api/core/index/Optional-decorator.html),
334
+ inject host element attributes with [`@Attribute`](../api/core/index/Attribute-interface.html),
335
+ inject content child queries with [`@ContentChild`](../api/core/index/ContentChild-decorator.html)
336
+ and inject view child queries with [`@ViewChild`](../api/core/index/ViewChild-decorator.html)).
355
337
356
- :marked
357
- We can apply other additional parameter decorators such as
358
- [`@Host`](../api/core/index/Host-decorator.html) and
359
- [`@SkipSelf`](../api/core/index/SkipSelf-decorator.html) in the same way -
360
- by adding `new ng.core.Host()` or `ng.core.SkipSelf()` in the
361
- parameters array.
338
+ In ES6 Javascript we just add the extra decorators to the nested injection parameters array.
362
339
340
+ To achieve the same effect in ES5 JavaScript, use the a nested array with the constructor
341
+ array notation in which the injection information precedes the constructor function itself.
342
+
343
+ We can apply other additional parameter decorators such as
344
+ [`@Host`](../api/core/index/Host-decorator.html) and
345
+ [`@SkipSelf`](../api/core/index/SkipSelf-decorator.html) in the same way -
346
+ by adding `new ng.core.Host()` or `ng.core.SkipSelf()` in the
347
+ parameters array.
348
+ + makeTabs(`
349
+ cb-ts-to-js/ts/app/hero-di-inject-additional.component.ts,
350
+ cb-ts-to-js/js-es6-decorators/app/hero-di-inject-additional.component.es6,
351
+ cb-ts-to-js/js-es6/app/hero-di-inject-additional.component.es6,
352
+ cb-ts-to-js/js/app/hero-di-inject-additional.component.js
353
+ ` ,`
354
+ ` ,`
355
+ Typescript,
356
+ ES6 Javascript with decorators,
357
+ ES6 Javascript,
358
+ ES5 Javascript
359
+ ` )
363
360
364
361
a( id ="other-property-metadata" )
365
362
.l-main-section
0 commit comments