5 lines
9.8 KiB
JSON

{
"id": "api/common/NgSwitch",
"title": "NgSwitch",
"contents": "\n\n<article>\n <div class=\"breadcrumb-container\">\n <div class=\"breadcrumb\">\n <script type=\"application/ld+json\">\n {\n \"@context\": \"http://schema.org\",\n \"@type\": \"BreadcrumbList\",\n \"itemListElement\": [\n { \"@type\": \"ListItem\", \"position\": 1, \"item\": { \"@id\": \"https://angular.io//api\", \"name\": \"API\" } },\n { \"@type\": \"ListItem\", \"position\": 2, \"item\": { \"@id\": \"https://angular.io/api/common\", \"name\": \"@angular/common\" } },\n { \"@type\": \"ListItem\", \"position\": 3, \"item\": { \"@id\": \"https://angular.io/api/common/NgSwitch\", \"name\": \"NgSwitch\" } }\n ]\n }\n </script>\n <a href=\"/api\">API</a> > <a href=\"api/common\">@angular/common</a>\n </div>\n <div class=\"github-links\">\n <a href=\"https://github.com/angular/angular/edit/master/packages/common/src/directives/ng_switch.ts?message=docs(common)%3A%20describe%20your%20change...#L35-L155\" aria-label=\"Suggest Edits\" title=\"Suggest Edits\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">mode_edit</i></a>\n <a href=\"https://github.com/angular/angular/tree/12.0.0-next.7/packages/common/src/directives/ng_switch.ts#L35-L155\" aria-label=\"View Source\" title=\"View Source\"><i class=\"material-icons\" aria-hidden=\"true\" role=\"img\">code</i></a>\n</div>\n </div>\n \n <header class=\"api-header\">\n <h1 id=\"ngswitch\">NgSwitch<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/NgSwitch#ngswitch\"><i class=\"material-icons\">link</i></a></h1>\n \n <label class=\"api-type-label directive\">directive</label>\n \n \n \n </header>\n \n <aio-toc class=\"embedded\"></aio-toc>\n\n <div class=\"api-body\">\n \n <section class=\"short-description\">\n <p>The <code>[<a href=\"api/common/NgSwitch\" class=\"code-anchor\">ngSwitch</a>]</code> directive on a container specifies an expression to match against.\nThe expressions to match are provided by <code><a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a></code> directives on views within the container.</p>\n<ul>\n<li>Every view that matches is rendered.</li>\n<li>If there are no matches, a view with the <code><a href=\"api/common/NgSwitchDefault\" class=\"code-anchor\">ngSwitchDefault</a></code> directive is rendered.</li>\n<li>Elements within the <code>[<a href=\"api/common/NgSwitch\" class=\"code-anchor\">NgSwitch</a>]</code> statement but outside of any <code><a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">NgSwitchCase</a></code>\nor <code><a href=\"api/common/NgSwitchDefault\" class=\"code-anchor\">ngSwitchDefault</a></code> directive are preserved at the location.</li>\n</ul>\n\n \n </section>\n \n \n \n \n<section class=\"see-also\">\n <h2 id=\"see-also\">See also<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/NgSwitch#see-also\"><i class=\"material-icons\">link</i></a></h2>\n <ul>\n \n <li><p><code><a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">NgSwitchCase</a></code></p>\n</li>\n <li><p><code><a href=\"api/common/NgSwitchDefault\" class=\"code-anchor\">NgSwitchDefault</a></code></p>\n</li>\n <li><p><a href=\"guide/structural-directives\">Structural Directives</a></p>\n</li>\n </ul>\n</section>\n\n\n <h2 id=\"ngmodule\">NgModule<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/NgSwitch#ngmodule\"><i class=\"material-icons\">link</i></a></h2>\n<ul class=\"ngmodule-list\">\n\n <li>\n <a href=\"api/common/CommonModule\">\n <code-example language=\"ts\" hidecopy=\"true\" class=\"no-box\">CommonModule</code-example>\n </a>\n </li>\n \n</ul>\n\n\n \n<section class=\"selector-list\">\n <h2 id=\"selectors\">Selectors<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/NgSwitch#selectors\"><i class=\"material-icons\">link</i></a></h2>\n \n <ul>\n <li><code>[<a href=\"api/common/NgSwitch\" class=\"code-anchor\">ngSwitch</a>]</code></li>\n \n </ul>\n \n</section>\n\n\n\n \n\n<section class=\"instance-properties\">\n <h2 id=\"properties\">Properties<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/NgSwitch#properties\"><i class=\"material-icons\">link</i></a></h2>\n <table class=\"is-full-width list-table property-table\">\n <thead>\n <tr>\n <th>Property</th>\n <th>Description</th>\n </tr>\n </thead>\n <tbody>\n \n <tr class=\"instance-property\">\n <td>\n <a id=\"ngSwitch\"></a>\n <code class=\"\"><span class=\"property-binding\">@<a href=\"api/core/Input\" class=\"code-anchor\">Input</a>()</span><br><span class=\"member-name\"><a href=\"api/common/NgSwitch\" class=\"code-anchor\">ngSwitch</a></span>: any</code>\n </td>\n <td><span class=\"write-only-property\">Write-Only</span>\n \n \n \n </td>\n </tr>\n \n </tbody>\n </table>\n</section>\n\n\n\n \n\n\n \n <section class=\"description\">\n <h2 id=\"description\">Description<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/NgSwitch#description\"><i class=\"material-icons\">link</i></a></h2>\n \n <p>Define a container element for the directive, and specify the switch expression\nto match against as an attribute:</p>\n<code-example>\n&#x3C;container-element [<a href=\"api/common/NgSwitch\" class=\"code-anchor\">ngSwitch</a>]=\"switch_expression\">\n</code-example>\n<p>Within the container, <code>*<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a></code> statements specify the match expressions\nas attributes. Include <code>*<a href=\"api/common/NgSwitchDefault\" class=\"code-anchor\">ngSwitchDefault</a></code> as the final case.</p>\n<code-example>\n&#x3C;container-element [<a href=\"api/common/NgSwitch\" class=\"code-anchor\">ngSwitch</a>]=\"switch_expression\">\n &#x3C;some-element *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_1\">...&#x3C;/some-element>\n...\n &#x3C;some-element *<a href=\"api/common/NgSwitchDefault\" class=\"code-anchor\">ngSwitchDefault</a>>...&#x3C;/some-element>\n&#x3C;/container-element>\n</code-example>\n<h3 id=\"usage-examples\">Usage Examples<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/NgSwitch#usage-examples\"><i class=\"material-icons\">link</i></a></h3>\n<p>The following example shows how to use more than one case to display the same view:</p>\n<code-example>\n&#x3C;container-element [<a href=\"api/common/NgSwitch\" class=\"code-anchor\">ngSwitch</a>]=\"switch_expression\">\n &#x3C;!-- the same view can be shown in more than one case -->\n &#x3C;some-element *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_1\">...&#x3C;/some-element>\n &#x3C;some-element *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_2\">...&#x3C;/some-element>\n &#x3C;some-other-element *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_3\">...&#x3C;/some-other-element>\n &#x3C;!--default case when there are no matches -->\n &#x3C;some-element *<a href=\"api/common/NgSwitchDefault\" class=\"code-anchor\">ngSwitchDefault</a>>...&#x3C;/some-element>\n&#x3C;/container-element>\n</code-example>\n<p>The following example shows how cases can be nested:</p>\n<code-example>\n&#x3C;container-element [<a href=\"api/common/NgSwitch\" class=\"code-anchor\">ngSwitch</a>]=\"switch_expression\">\n &#x3C;some-element *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_1\">...&#x3C;/some-element>\n &#x3C;some-element *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_2\">...&#x3C;/some-element>\n &#x3C;some-other-element *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_3\">...&#x3C;/some-other-element>\n &#x3C;ng-container *<a href=\"api/common/NgSwitchCase\" class=\"code-anchor\">ngSwitchCase</a>=\"match_expression_3\">\n &#x3C;!-- use a ng-container to group <a href=\"api/forms/SelectMultipleControlValueAccessor\" class=\"code-anchor\">multiple</a> root nodes -->\n &#x3C;inner-element>&#x3C;/inner-element>\n &#x3C;inner-other-element>&#x3C;/inner-other-element>\n &#x3C;/ng-container>\n &#x3C;some-element *<a href=\"api/common/NgSwitchDefault\" class=\"code-anchor\">ngSwitchDefault</a>>...&#x3C;/some-element>\n &#x3C;/container-element>\n</code-example>\n\n </section>\n \n\n \n\n \n\n \n\n \n \n \n\n </div>\n</article>\n\n<!-- links to this doc:\n - api/common\n - api/common/CommonModule\n - api/common/NgSwitchCase\n - api/common/NgSwitchDefault\n - guide/ajs-quick-reference\n - guide/built-in-directives\n - guide/cheatsheet\n - guide/dynamic-form\n - guide/structural-directives\n-->\n<!-- links from this doc:\n - /api\n - api/common\n - api/common/CommonModule\n - api/common/NgSwitch#description\n - api/common/NgSwitch#ngmodule\n - api/common/NgSwitch#ngswitch\n - api/common/NgSwitch#properties\n - api/common/NgSwitch#see-also\n - api/common/NgSwitch#selectors\n - api/common/NgSwitch#usage-examples\n - api/common/NgSwitchCase\n - api/common/NgSwitchDefault\n - api/core/Input\n - api/forms/SelectMultipleControlValueAccessor\n - guide/structural-directives\n - https://github.com/angular/angular/edit/master/packages/common/src/directives/ng_switch.ts?message=docs(common)%3A%20describe%20your%20change...#L35-L155\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/common/src/directives/ng_switch.ts#L35-L155\n-->"
}