5 lines
27 KiB
JSON

{
"id": "api/common/KeyValuePipe",
"title": "KeyValuePipe",
"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/KeyValuePipe\", \"name\": \"KeyValuePipe\" } }\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/pipes/keyvalue_pipe.ts?message=docs(common)%3A%20describe%20your%20change...#L25-L104\" 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/pipes/keyvalue_pipe.ts#L25-L104\" 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=\"keyvaluepipe\">KeyValuePipe<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/KeyValuePipe#keyvaluepipe\"><i class=\"material-icons\">link</i></a></h1>\n \n <label class=\"api-type-label pipe\">pipe</label>\n \n \n <label class=\"api-status-label impure-pipe\">impure</label>\n </header>\n \n <aio-toc class=\"embedded\"></aio-toc>\n\n <div class=\"api-body\">\n \n <section class=\"short-description\">\n <p>Transforms Object or Map into an array of key value pairs.</p>\n\n <p><a href=\"api/common/KeyValuePipe#description\">See more...</a></p>\n </section>\n \n \n \n<section class=\"pipe-overview\">\n <code-example hidecopy=\"true\" class=\"no-box api-heading\">{{ input_expression | <span class=\"kwd nocode\">keyvalue</span> [ : compareFn ] }}</code-example>\n\n <h2 id=\"ngmodule\">NgModule<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/KeyValuePipe#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 \n <h2 id=\"input-value\">Input value<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/KeyValuePipe#input-value\"><i class=\"material-icons\">link</i></a></h2>\n <table class=\"is-full-width list-table parameters-table pipe-parameters\">\n <tbody>\n \n <tr class=\"pipe-parameter\">\n <td class=\"param-name\">\n <a id=\"\"></a>\n <code>input</code>\n </td>\n <td class=\"param-type\"><code>{ [key: string]: V; [key: number]: V; } | ReadonlyMap<k, v=\"\"></k,></code></td>\n <td class=\"param-description\">\n \n \n </td>\n </tr>\n </tbody>\n</table>\n \n \n <h2 id=\"parameters\">Parameters<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/KeyValuePipe#parameters\"><i class=\"material-icons\">link</i></a></h2>\n <table class=\"is-full-width list-table parameters-table pipe-parameters\">\n <tbody>\n \n <tr class=\"pipe-parameter\">\n <td class=\"param-name\">\n <a id=\"\"></a>\n <code>compareFn</code>\n </td>\n <td class=\"param-type\"><code>(<a href=\"api/router/RouterLinkWithHref\" class=\"code-anchor\">a</a>: <a href=\"api/common/KeyValue\" class=\"code-anchor\">KeyValue</a><k, v=\"\">, b: KeyValue<k, v=\"\">) => number</k,></k,></code></td>\n <td class=\"param-description\">\n <p>Optional. Default is <code>defaultComparator</code>.</p>\n \n </td>\n </tr>\n </tbody>\n</table>\n \n</section>\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/KeyValuePipe#description\"><i class=\"material-icons\">link</i></a></h2>\n <p>The output array will be ordered by keys.\nBy default the comparator will be by Unicode point value.\nYou can optionally pass a compareFn if your keys are complex types.</p>\n\n <p>Further information available in the <a href=\"api/common/KeyValuePipe#usage-notes\">Usage Notes</a>...</p>\n</section>\n\n\n \n<section class=\"usage-notes\">\n <h2 id=\"usage-notes\">Usage notes<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/KeyValuePipe#usage-notes\"><i class=\"material-icons\">link</i></a></h2>\n <h3 id=\"examples\">Examples<a title=\"Link to this heading\" class=\"header-link\" aria-hidden=\"true\" href=\"api/common/KeyValuePipe#examples\"><i class=\"material-icons\">link</i></a></h3>\n<p>This examples show how an Object or a Map can be iterated by ngFor with the use of this\nkeyvalue pipe.</p>\n<code-example path=\"common/pipes/ts/keyvalue_pipe.ts\" region=\"KeyValuePipe\">\n@<a href=\"api/core/Component\" class=\"code-anchor\">Component</a>({\n selector: 'keyvalue-pipe',\n template: `&#x3C;span>\n &#x3C;p>Object&#x3C;/p>\n &#x3C;div *<a href=\"api/common/NgForOf\" class=\"code-anchor\">ngFor</a>=\"let item of object | <a href=\"api/common/KeyValuePipe\" class=\"code-anchor\">keyvalue</a>\">\n {{item.key}}:{{item.value}}\n &#x3C;/div>\n &#x3C;p>Map&#x3C;/p>\n &#x3C;div *<a href=\"api/common/NgForOf\" class=\"code-anchor\">ngFor</a>=\"let item of map | <a href=\"api/common/KeyValuePipe\" class=\"code-anchor\">keyvalue</a>\">\n {{item.key}}:{{item.value}}\n &#x3C;/div>\n &#x3C;/span>`\n})\nexport class KeyValuePipeComponent {\n object: {[key: number]: string} = {2: 'foo', 1: 'bar'};\n map = new Map([[2, 'foo'], [1, 'bar']]);\n}\n\n</code-example>\n\n</section>\n\n\n\n </div>\n</article>\n\n<!-- links to this doc:\n - api/common\n - api/common/CommonModule\n - api/core/PipeTransform\n-->\n<!-- links from this doc:\n - /api\n - api/common\n - api/common/CommonModule\n - api/common/KeyValue\n - api/common/KeyValuePipe#description\n - api/common/KeyValuePipe#examples\n - api/common/KeyValuePipe#input-value\n - api/common/KeyValuePipe#keyvaluepipe\n - api/common/KeyValuePipe#ngmodule\n - api/common/KeyValuePipe#parameters\n - api/common/KeyValuePipe#usage-notes\n - api/common/NgForOf\n - api/core/Component\n - api/router/RouterLinkWithHref\n - https://github.com/angular/angular/edit/master/packages/common/src/pipes/keyvalue_pipe.ts?message=docs(common)%3A%20describe%20your%20change...#L25-L104\n - https://github.com/angular/angular/tree/12.0.0-next.7/packages/common/src/pipes/keyvalue_pipe.ts#L25-L104\n-->"
}