Skip to content

Commit 20953ed

Browse files
vicbtbosch
authored andcommitted
doc(Directive): update docs for Directive.host
1 parent f3b4937 commit 20953ed

2 files changed

Lines changed: 37 additions & 42 deletions

File tree

modules/angular2/docs/core/02_directives.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ Here is a trivial example of a tooltip decorator. The directive will log a toolt
6666
properties: [ | List which properties need to be bound
6767
'text: tooltip' | - DOM element tooltip property should be
6868
], | mapped to the directive text property.
69-
hostListeners: { | List which events need to be mapped.
70-
mouseover: 'show' | - Invoke the show() method every time
69+
host: { | List which events need to be mapped.
70+
(mouseover): 'show()' | - Invoke the show() method every time
7171
} | the mouseover event is fired.
7272
}) |
7373
class Form { | Directive controller class, instantiated

modules/angular2/src/core/annotations_impl/annotations.ts

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -585,12 +585,13 @@ export class Directive extends Injectable {
585585
*/
586586
events: List<string>;
587587

588-
// TODO(vicb): doc
589-
590588
/**
591-
* Specifies which DOM hostListeners a directive listens to.
589+
* Specifiy the events, actions, properties and attributes related to the host element.
590+
*
591+
* ## Events
592592
*
593-
* The `hostListeners` property defines a set of `event` to `method` key-value pairs:
593+
* Specifies which DOM hostListeners a directive listens to via a set of `(event)` to `method`
594+
* key-value pairs:
594595
*
595596
* - `event1`: the DOM event that the directive listens to.
596597
* - `statement`: the statement to execute when the event occurs.
@@ -603,101 +604,97 @@ export class Directive extends Injectable {
603604
* When writing a directive event binding, you can also refer to the following local variables:
604605
* - `$event`: Current event object which triggered the event.
605606
* - `$target`: The source of the event. This will be either a DOM element or an Angular
606-
* directive.
607-
* (will be implemented in later release)
608-
*
607+
* directive. (will be implemented in later release)
609608
*
610609
* ## Syntax
611610
*
612611
* ```
613612
* @Directive({
614-
* hostListeners: {
615-
* 'event1': 'onMethod1(arguments)',
616-
* 'target:event2': 'onMethod2(arguments)',
613+
* host: {
614+
* '(event1)': 'onMethod1(arguments)',
615+
* '(target:event2)': 'onMethod2(arguments)',
617616
* ...
618617
* }
619618
* }
620619
* ```
621620
*
622621
* ## Basic Event Binding:
623622
*
624-
* Suppose you want to write a directive that triggers on `change` events in the DOM and on
623+
* Suppose you want to write a directive that reacts to `change` events in the DOM and on
625624
* `resize` events in window.
626625
* You would define the event binding as follows:
627626
*
628627
* ```
629628
* @Directive({
630629
* selector: 'input',
631-
* hostListeners: {
632-
* 'change': 'onChange($event)',
633-
* 'window:resize': 'onResize($event)'
630+
* host: {
631+
* '(change)': 'onChange($event)',
632+
* '(window:resize)': 'onResize($event)'
634633
* }
635634
* })
636635
* class InputDirective {
637636
* onChange(event:Event) {
637+
* // invoked when the input element fires the 'change' event
638638
* }
639639
* onResize(event:Event) {
640+
* // invoked when the window fires the 'resize' event
640641
* }
641642
* }
642643
* ```
643644
*
644-
* Here the `onChange` method of `InputDirective` is invoked whenever the DOM element fires the
645-
* 'change' event.
645+
* ## Properties
646646
*
647-
*/
648-
/**
649647
* Specifies which DOM properties a directives updates.
650648
*
651649
* ## Syntax
652650
*
653651
* ```
654652
* @Directive({
655653
* selector: 'input',
656-
* hostProperties: {
657-
* 'value': 'value'
654+
* host: {
655+
* '[prop]': 'expression'
658656
* }
659657
* })
660658
* class InputDirective {
661659
* value:string;
662660
* }
663-
*
664-
* In this example every time the value property of the decorator changes, Angular will update the
665-
* value property of
666-
* the host element.
667661
* ```
668-
*/
669-
/**
662+
*
663+
* In this example the prop property of the host element is updated with the expression value
664+
* every time it changes.
665+
*
666+
* ## Attributes
667+
*
670668
* Specifies static attributes that should be propagated to a host element. Attributes specified
671-
* in `hostAttributes`
672-
* are propagated only if a given attribute is not present on a host element.
669+
* in `hostAttributes` are propagated only if a given attribute is not present on a host element.
673670
*
674671
* ## Syntax
675672
*
676673
* ```
677674
* @Directive({
678675
* selector: '[my-button]',
679-
* hostAttributes: {
676+
* host: {
680677
* 'role': 'button'
681678
* }
682679
* })
683680
* class MyButton {
684681
* }
682+
* ```
685683
*
686684
* In this example using `my-button` directive (ex.: `<div my-button></div>`) on a host element
687-
* (here: `<div>` )
688-
* will ensure that this element will get the "button" role.
689-
* ```
690-
*/
691-
/**
685+
* (here: `<div>` ) will ensure that this element will get the "button" role.
686+
*
687+
* ## Actions
688+
*
692689
* Specifies which DOM methods a directive can invoke.
693690
*
694691
* ## Syntax
695692
*
696693
* ```
697694
* @Directive({
698695
* selector: 'input',
699-
* hostActions: {
700-
* 'emitFocus': 'focus()'
696+
* host: {
697+
* '@emitFocus': 'focus()'
701698
* }
702699
* })
703700
* class InputDirective {
@@ -709,12 +706,10 @@ export class Directive extends Injectable {
709706
* this.emitFocus.next();
710707
* }
711708
* }
712-
*
713-
* In this example calling focus on InputDirective will result in calling focus on the DOM
714-
* element.
715709
* ```
710+
*
711+
* In this example calling focus on InputDirective will result in calling focus on the input.
716712
*/
717-
718713
host: StringMap<string, string>;
719714

720715
/**

0 commit comments

Comments
 (0)