@@ -22,58 +22,44 @@ export class SwitchView {
2222}
2323
2424/**
25- * Adds or removes DOM sub-trees when their match expressions match the switch expression.
26- *
27- * Elements within `NgSwitch` but without `NgSwitchCase` or `NgSwitchDefault` directives will be
28- * preserved at the location as specified in the template.
29- *
30- * `NgSwitch` simply inserts nested elements based on which match expression matches the value
31- * obtained from the evaluated switch expression. In other words, you define a container element
32- * (where you place the directive with a switch expression on the
33- * `[ngSwitch]="..."` attribute), define any inner elements inside of the directive and
34- * place a `[ngSwitchCase]` attribute per element.
35- *
36- * The `ngSwitchCase` property is used to inform `NgSwitch` which element to display when the
37- * expression is evaluated. If a matching expression is not found via a `ngSwitchCase` property
38- * then an element with the `ngSwitchDefault` attribute is displayed.
39- *
40- * ### Example ([live demo](http://plnkr.co/edit/DQMTII95CbuqWrl3lYAs?p=preview))
41- *
42- * ```typescript
43- * @Component({
44- * selector: 'app',
45- * template: `
46- * <p>Value = {{value}}</p>
47- * <button (click)="inc()">Increment</button>
48- *
49- * <div [ngSwitch]="value">
50- * <p *ngSwitchCase="'init'">increment to start</p>
51- * <p *ngSwitchCase="0">0, increment again</p>
52- * <p *ngSwitchCase="1">1, increment again</p>
53- * <p *ngSwitchCase="2">2, stop incrementing</p>
54- * <p *ngSwitchDefault>> 2, STOP!</p>
55- * </div>
56- *
57- * <!-- alternate syntax -->
58- *
59- * <p [ngSwitch]="value">
60- * <template ngSwitchCase="init">increment to start</template>
61- * <template [ngSwitchCase]="0">0, increment again</template>
62- * <template [ngSwitchCase]="1">1, increment again</template>
63- * <template [ngSwitchCase]="2">2, stop incrementing</template>
64- * <template ngSwitchDefault>> 2, STOP!</template>
65- * </p>
66- * `,
67- * directives: [NgSwitch, NgSwitchCase, NgSwitchDefault]
68- * })
69- * export class App {
70- * value = 'init';
71- *
72- * inc() {
73- * this.value = this.value === 'init' ? 0 : this.value + 1;
74- * }
75- * }
25+ * @ngModule CommonModule
26+ *
27+ * @whatItDoes Adds / removes DOM sub-trees when the nest match expressions matches the switch
28+ * expression.
29+ *
30+ * @howToUse
7631 * ```
32+ * <container-element [ngSwitch]="switch_expression">
33+ * <some-element *ngSwitchCase="match_expression_1">...</some-element>
34+ * <some-element *ngSwitchCase="match_expression_2">...</some-element>
35+ * <some-other-element *ngSwitchCase="match_expression_3">...</some-other-element>
36+ * <ng-container *ngSwitchCase="match_expression_3">
37+ * <!-- use a ng-container to group multiple root nodes -->
38+ * <inner-element></inner-element>
39+ * <inner-other-element></inner-other-element>
40+ * </ng-container>
41+ * <some-element *ngSwitchDefault>...</p>
42+ * </container-element>
43+ * ```
44+ * @description
45+ *
46+ * `NgSwitch` stamps out nested views when their match expression value matches the value of the
47+ * switch expression.
48+ *
49+ * In other words:
50+ * - you define a container element (where you place the directive with a switch expression on the
51+ * `[ngSwitch]="..."` attribute)
52+ * - you define inner views inside the `NgSwitch` and place a `*ngSwitchCase` attribute on the view
53+ * root elements.
54+ *
55+ * Elements within `NgSwitch` but outside of a `NgSwitchCase` or `NgSwitchDefault` directives will
56+ * be
57+ * preserved at the location.
58+ *
59+ * The `ngSwitchCase` directive informs the parent `NgSwitch` of which view to display when the
60+ * expression is evaluated.
61+ * When no matching expression is found on a `ngSwitchCase` view, the `ngSwitchDefault` view is
62+ * stamped out.
7763 *
7864 * @stable
7965 */
@@ -169,10 +155,23 @@ export class NgSwitch {
169155}
170156
171157/**
172- * Insert the sub-tree when the `ngSwitchCase` expression evaluates to the same value as the
173- * enclosing switch expression.
158+ * @ngModule CommonModule
174159 *
175- * If multiple match expression match the switch expression value, all of them are displayed.
160+ * @whatItDoes Creates a view that will be added/removed from the parent {@link NgSwitch} when the
161+ * given expression evaluate to respectively the same/different value as the switch
162+ * expression.
163+ *
164+ * @howToUse
165+ * <container-element [ngSwitch]="switch_expression">
166+ * <some-element *ngSwitchCase="match_expression_1">...</some-element>
167+ * </container-element>
168+ *
169+ * @description
170+ *
171+ * Insert the sub-tree when the expression evaluates to the same value as the enclosing switch
172+ * expression.
173+ *
174+ * If multiple match expressions match the switch expression value, all of them are displayed.
176175 *
177176 * See {@link NgSwitch} for more details and example.
178177 *
@@ -202,8 +201,21 @@ export class NgSwitchCase {
202201}
203202
204203/**
205- * Default case statements are displayed when no match expression matches the switch expression
206- * value.
204+ * @ngModule CommonModule
205+ * @whatItDoes Creates a view that is added to the parent {@link NgSwitch} when no case expressions
206+ * match the
207+ * switch expression.
208+ *
209+ * @howToUse
210+ * <container-element [ngSwitch]="switch_expression">
211+ * <some-element *ngSwitchCase="match_expression_1">...</some-element>
212+ * <some-other-element *ngSwitchDefault>...</some-other-element>
213+ * </container-element>
214+ *
215+ * @description
216+ *
217+ * Insert the sub-tree when no case expressions evaluate to the same value as the enclosing switch
218+ * expression.
207219 *
208220 * See {@link NgSwitch} for more details and example.
209221 *
0 commit comments