@@ -556,7 +556,7 @@ export class Component extends Directive {
556
556
}
557
557
558
558
/**
559
- * A directive used for dynamically loading components.
559
+ * Directive used for dynamically loading components.
560
560
*
561
561
* Regular angular components are statically resolved. DynamicComponent allows to you resolve a component at runtime
562
562
* instead by providing a placeholder into which a regular angular component can be dynamically loaded. Once loaded,
@@ -637,9 +637,9 @@ export class DynamicComponent extends Directive {
637
637
/**
638
638
* Directive that attaches behavior to DOM elements.
639
639
*
640
- * A decorator directive attaches behavior to a DOM element in a composable manner.
640
+ * A decorator directive attaches behavior to a DOM element in a composable manner.
641
641
* (see: http://en.wikipedia.org/wiki/Composition_over_inheritance)
642
- *
642
+ *
643
643
* Decorators:
644
644
* - are simplest form of [Directive]s.
645
645
* - are best used as a composition pattern ()
@@ -652,7 +652,7 @@ export class DynamicComponent extends Directive {
652
652
*
653
653
* ## Example
654
654
*
655
- * Here we use a decorator directive to simply define basic tool-tip behavior.
655
+ * Here we use a decorator directive to simply define basic tool-tip behavior.
656
656
*
657
657
* ```
658
658
* @Decorator ({
@@ -685,9 +685,9 @@ export class DynamicComponent extends Directive {
685
685
* }
686
686
* }
687
687
* ```
688
- * In our HTML template, we can then add this behavior to a `<div>` or any other element with the `tooltip` selector,
688
+ * In our HTML template, we can then add this behavior to a `<div>` or any other element with the `tooltip` selector,
689
689
* like so:
690
- *
690
+ *
691
691
* ```
692
692
* <div tooltip="some text here"></div>
693
693
* ```
@@ -728,24 +728,45 @@ export class Decorator extends Directive {
728
728
}
729
729
730
730
/**
731
- * Viewport is used for controlling the instatiation of inline templates. [TODO: needs co-work :)]
731
+ * Directive that controls the instantiation, destruction, and positioning of inline template elements.
732
732
*
733
- * Viewport consist of a controller which can inject [ViewContainer]. A [ViewContainer] represents a location in the
734
- * current view where child views can be inserted. [ViewContainer] is created as a result of `<template>` element.
733
+ * A viewport directive uses a [ViewContainer] to instantiate, insert, move, and destroy views at runtime.
734
+ * The [ViewContainer] is created as a result of `<template>` element, and represents a location in the current view
735
+ * where these actions are performed.
735
736
*
736
- * NOTE: `<template>` directives can be created in shorthand form as `<TAG template="...">` or `<TAG *key="...">`
737
+ * Views are always created as children of the current [View], and as siblings of the `<template>` element. Thus a
738
+ * directive in a child view cannot inject the viewport directive that created it.
737
739
*
738
- * ## Example
740
+ * Since viewport directives are common in Angular, and using the full `<template>` element syntax is wordy, Angular
741
+ * also supports a shorthand notation: `<li *foo="bar">` and `<li template="foo: bar">` are equivalent.
739
742
*
740
- * Given folowing inline template, let's implement the `unless` behavior.
743
+ * Thus,
741
744
*
742
745
* ```
743
746
* <ul>
744
- * <li *unless="expr"></li>
747
+ * <li *foo="bar" title="text"></li>
748
+ * </ul>
749
+ * ```
750
+ *
751
+ * Expands in use to:
752
+ *
753
+ * ```
754
+ * <ul>
755
+ * <template [foo]="bar">
756
+ * <li title="text"></li>
757
+ * </template>
745
758
* </ul>
746
759
* ```
747
760
*
748
- * Can be implemented using:
761
+ * Notice that although the shorthand places `*foo="bar"` within the `<li>` element, the binding for the `Viewport`
762
+ * controller is correctly instantiated on the `<template>` element rather than the `<li>` element.
763
+ *
764
+ *
765
+ * ## Example
766
+ *
767
+ * Let's suppose we want to implement the `unless` behavior, to conditionally include a template.
768
+ *
769
+ * Here is a simple viewport directive that triggers on an `unless` selector:
749
770
*
750
771
* ```
751
772
* @Viewport ({
@@ -754,7 +775,7 @@ export class Decorator extends Directive {
754
775
* 'condition': 'unless'
755
776
* }
756
777
* })
757
- * export class If {
778
+ * export class Unless {
758
779
* viewContainer: ViewContainer;
759
780
* prevCondition: boolean;
760
781
*
@@ -775,20 +796,14 @@ export class Decorator extends Directive {
775
796
* }
776
797
* ```
777
798
*
778
- * To better undarstand what is hapening, remember that angular converts the above template to:
779
- *
799
+ * We can then use this `unless` selector in a template:
780
800
* ```
781
801
* <ul>
782
- * <template [unless]="exp">
783
- * <li></li>
784
- * </template>
802
+ * <li *unless="expr"></li>
785
803
* </ul>
786
804
* ```
787
805
*
788
- * Notice that the `*unless="exp"` got hoisted to `<template>`. This means that the `Viewport` controller is instantiated
789
- * on the `<template>` element rather thna the `<li>` element.
790
- *
791
- * Once the viewport insntantiates the child view the result is:
806
+ * Once the viewport instantiates the child view, the shorthand notation for the template expands and the result is:
792
807
*
793
808
* ```
794
809
* <ul>
@@ -799,9 +814,8 @@ export class Decorator extends Directive {
799
814
* </ul>
800
815
* ```
801
816
*
802
- * The key thing to notice here is that `<li>` instance is a sibling of `<template>` not a child. For this reason
803
- * it is not possible to inject `Viewport` directive into other directives, (`Viweport` directives are always on
804
- * `<template>` elements which are leafs.)
817
+ * Note also that although the `<li></li>` template still exists inside the `<template></template>`, the instantiated
818
+ * view occurs on the second `<li></li>` which is a sibling to the `<template>` element.
805
819
*
806
820
*
807
821
* @publicModule angular2/annotations
@@ -831,7 +845,7 @@ export class Viewport extends Directive {
831
845
//TODO(misko): turn into LifecycleEvent class once we switch to TypeScript;
832
846
833
847
/**
834
- * Specify that a directive should be notified whenever a [View] that contains it is destroyed.
848
+ * Notify a directive whenever a [View] that contains it is destroyed.
835
849
*
836
850
* ## Example
837
851
*
@@ -852,7 +866,7 @@ export const onDestroy = "onDestroy";
852
866
853
867
854
868
/**
855
- * Specify that a directive should be notified when any of its bindings have changed.
869
+ * Notify a directive when any of its bindings have changed.
856
870
*
857
871
* ## Example:
858
872
*
0 commit comments