Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit e453d3b

Browse files
committed
add host and query metadata section
1 parent 954144c commit e453d3b

File tree

3 files changed

+107
-95
lines changed

3 files changed

+107
-95
lines changed

public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-bindings.component.es6

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { BrowserModule } from '@angular/platform-browser';
99
// #docregion
1010
@Component({
1111
selector: 'heroes-bindings',
12-
template: `<h1 [class.active]="active">
13-
Tour of Heroes
14-
</h1>`
12+
template: `
13+
<h1 [class.active]="active">
14+
Tour of Heroes
15+
</h1>
16+
`
1517
})
1618
class HeroesComponent {
1719
@HostBinding() title = 'Tooltip content';
18-
@HostBinding('class.heading')
19-
hClass = true;
20+
@HostBinding('class.heading') hClass = true;
2021
active;
2122

2223
constructor() {}

public/docs/_examples/cb-ts-to-js/ts/app/heroes-bindings.component.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { BrowserModule } from '@angular/platform-browser';
99
// #docregion
1010
@Component({
1111
selector: 'heroes-bindings',
12-
template: `<h1 [class.active]="active">
13-
Tour of Heroes
14-
</h1>`
12+
template: `
13+
<h1 [class.active]="active">
14+
Tour of Heroes
15+
</h1>
16+
`
1517
})
1618
class HeroesComponent {
1719
@HostBinding() title = 'Tooltip content';
18-
@HostBinding('class.heading')
19-
hClass = true;
20+
@HostBinding('class.heading') hClass = true;
2021
active: boolean;
2122

2223
constructor() {}

public/docs/js/latest/cookbook/ts-to-js.jade

Lines changed: 95 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include ../../../../_includes/_util-fns
2424

2525
[Dependency Injection](#dependency-injection)
2626

27-
[Host and Query Metadata](#other-property-metadata)
27+
[Host and Query Metadata](#host-query-metadata)
2828

2929
**Run and compare the live <live-example name="cb-ts-to-js">TypeScript</live-example> and <live-example name="cb-ts-to-js" lang="js">JavaScript</live-example>
3030
code shown in this cookbook.**
@@ -358,92 +358,102 @@ a(id="property-metadata")
358358
ES5 Javascript
359359
`)
360360

361-
a(id="other-property-metadata")
361+
a(id="host-query-metadata")
362362
.l-main-section
363363
:marked
364364
## Host and Query Metadata
365365

366-
- var top="vertical-align:top"
367-
table(width="100%")
368-
col(width="50%")
369-
col(width="50%")
370-
tr
371-
th TypeScript
372-
th ES5 JavaScript
373-
tr(style=top)
366+
### Host Decorators
367+
368+
In Typescript and ES6 with decorators we can use host property decorators to bind a host
369+
element to a component or directive.
370+
The [`@HostBinding`](../api/core/index/HostBinding-interface.html) decorator
371+
binds host element properties to component data properties.
372+
The [`@HostListener`](../api/core/index/HostListener-interface.html) decorator binds
373+
host element events to component event handlers.
374+
375+
When using ES5/6 we add a `host` attribute to the component metadata to achieve the
376+
same effect as `@HostBinding` and `@HostListener`.
377+
378+
The `host` value is an object whose properties are host property and listener bindings:
374379

375-
td
376-
:marked
377-
### Host Decorators
378-
379-
We can use host property decorators to bind a host element to a component or directive.
380-
The [`@HostBinding`](../api/core/index/HostBinding-interface.html) decorator
381-
binds host element properties to component data properties.
382-
The [`@HostListener`](../api/core/index/HostListener-interface.html) decorator bimds
383-
host element events to component event handlers.
384-
385-
+makeExample('cb-ts-to-js/ts/app/heroes-bindings.component.ts')(format="." )
386-
387-
.alert.is-helpful
388-
:marked
389-
In TypeScript we can also use `host` metadata
390-
instead of the `@HostBinding` and `@HostListener` property decorators.
391-
td
392-
:marked
393-
### Host Metadata
394-
395-
We add a `host` attribute to the component metadata to achieve the
396-
same effect as `@HostBinding` and `@HostListener`.
397-
398-
The `host` value is an object whose properties are host property and listener bindings:
399-
400-
* Each key follows regular Angular binding syntax: `[property]` for host bindings
401-
or `(event)` for host listeners.
402-
* Each value identifies the corresponding component property or method.
403-
404-
+makeExample('cb-ts-to-js/js/app/heroes-bindings.component.js')(format="." )
405-
406-
tr(style=top)
407-
td
408-
:marked
409-
### Query Decorators
410-
411-
There are several property decorators for querying the descendants of
412-
a component or directive.
413-
414-
The [`@ViewChild`](../api/core/index/ViewChild-decorator.html) and
415-
[`@ViewChildren`](../api/core/index/ViewChildren-decorator.html) property decorators
416-
allow a component to query instances of other components that are used in
417-
its view.
418-
419-
+makeExample('cb-ts-to-js/ts/app/heroes-queries.component.ts', 'view')(format="." )
420-
421-
:marked
422-
The [`@ContentChild`](../api/core/index/ContentChild-decorator.html) and
423-
[`@ContentChildren`](../api/core/index/ContentChildren-decorator.html) property decorators
424-
allow a component to query instances of other components that have been projected
425-
into its view from elsewhere.
426-
427-
+makeExample('cb-ts-to-js/ts/app/heroes-queries.component.ts', 'content')(format="." )
428-
429-
.alert.is-helpful
430-
:marked
431-
In TypeScript we can also use the `queries` metadata
432-
instead of the `@ViewChild` and `@ContentChild` property decorators.
433-
td
434-
:marked
435-
### Query Metadata
436-
437-
We access a component's view children by adding a `queries` attribute to
438-
the component metadata. It should be an object where:
439-
440-
* Each key is the name of a component property that will hold the view children
441-
* Each value is an instance of either `ViewChild` or `ViewChildren`.
442-
443-
+makeExample('cb-ts-to-js/js/app/heroes-queries.component.js', 'view')(format="." )
444-
445-
:marked
446-
We add *content* child queries to the same `queries` attribute
447-
in the same manner, using instances of `ContentChild` or `ContentChildren`:
448-
449-
+makeExample('cb-ts-to-js/js/app/heroes-queries.component.js', 'content')(format="." )
380+
* Each key follows regular Angular binding syntax: `[property]` for host bindings
381+
or `(event)` for host listeners.
382+
* Each value identifies the corresponding component property or method.
383+
384+
+makeTabs(`
385+
cb-ts-to-js/ts/app/heroes-bindings.component.ts,
386+
cb-ts-to-js/js-es6-decorators/app/heroes-bindings.component.es6,
387+
cb-ts-to-js/js-es6/app/heroes-bindings.component.es6,
388+
cb-ts-to-js/js/app/heroes-bindings.component.js
389+
`,`
390+
`,`
391+
Typescript,
392+
ES6 Javascript with decorators,
393+
ES6 Javascript,
394+
ES5 Javascript
395+
`)
396+
.alert.is-helpful
397+
:marked
398+
In TypeScript and ES6 with decorators we can also use the `queries` metadata
399+
instead of the `@ViewChild` and `@ContentChild` property decorators.
400+
401+
:marked
402+
### Query Decorators
403+
404+
There are several property decorators for querying the descendants of
405+
a component or directive.
406+
407+
The [`@ViewChild`](../api/core/index/ViewChild-decorator.html) and
408+
[`@ViewChildren`](../api/core/index/ViewChildren-decorator.html) property decorators
409+
allow a component to query instances of other components that are used in
410+
its view.
411+
412+
In ES5/6 Javascript we access a component's view children by adding a `queries` attribute to
413+
the component metadata. It should be an object where:
414+
415+
* Each key is the name of a component property that will hold the view children
416+
* Each value is an instance of either `ViewChild` or `ViewChildren`.
417+
418+
+makeTabs(`
419+
cb-ts-to-js/ts/app/heroes-queries.component.ts,
420+
cb-ts-to-js/js-es6-decorators/app/heroes-queries.component.es6,
421+
cb-ts-to-js/js-es6/app/heroes-queries.component.es6,
422+
cb-ts-to-js/js/app/heroes-queries.component.js
423+
`,`
424+
view,
425+
view,
426+
view,
427+
view
428+
`,`
429+
Typescript,
430+
ES6 Javascript with decorators,
431+
ES6 Javascript,
432+
ES5 Javascript
433+
`)
434+
435+
:marked
436+
The [`@ContentChild`](../api/core/index/ContentChild-decorator.html) and
437+
[`@ContentChildren`](../api/core/index/ContentChildren-decorator.html) property decorators
438+
allow a component to query instances of other components that have been projected
439+
into its view from elsewhere.
440+
441+
They can be added in the same way as [`@ViewChild`](../api/core/index/ViewChild-decorator.html) and
442+
[`@ViewChildren`](../api/core/index/ViewChildren-decorator.html).
443+
444+
+makeTabs(`
445+
cb-ts-to-js/ts/app/heroes-queries.component.ts,
446+
cb-ts-to-js/js-es6-decorators/app/heroes-queries.component.es6,
447+
cb-ts-to-js/js-es6/app/heroes-queries.component.es6,
448+
cb-ts-to-js/js/app/heroes-queries.component.js
449+
`,`
450+
content,
451+
content,
452+
content,
453+
content
454+
`,`
455+
Typescript,
456+
ES6 Javascript with decorators,
457+
ES6 Javascript,
458+
ES5 Javascript
459+
`)

0 commit comments

Comments
 (0)