{"id":1114,"date":"2023-06-27T05:00:00","date_gmt":"2023-06-27T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1114"},"modified":"2023-06-23T15:24:09","modified_gmt":"2023-06-23T22:24:09","slug":"how-to-pass-multiple-pieces-of-content-from-one-component-to-another","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/how-to-pass-multiple-pieces-of-content-from-one-component-to-another\/","title":{"rendered":"How to pass multiple pieces of content from one component to another?"},"content":{"rendered":"\n<p>Yesterday, we saw that we could use <a href=\"https:\/\/blog.angulartraining.com\/how-to-pass-custom-content-to-an-angular-component-83a77da9f5be\" target=\"_blank\" rel=\"noopener\" title=\"\">content projection<\/a> to pass an HTML template from one component to another. But what if we want to pass multiple different templates? We can use multi-slot content projection.<\/p>\n\n\n\n<p>Here&#8217;s what we want to achieve:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"294\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-33-1024x294.png\" alt=\"\" class=\"wp-image-1115\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-33-1024x294.png 1024w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-33-300x86.png 300w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-33-768x220.png 768w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-33.png 1045w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In our reusable dialog component, we will have multiple <code>ng-content<\/code> elements. Each <code>ng-content<\/code> will have a specific query selecting a template to render:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"606\" height=\"199\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-34.png\" alt=\"\" class=\"wp-image-1116\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-34.png 606w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-34-300x99.png 300w\" sizes=\"auto, (max-width: 606px) 100vw, 606px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>These queries use the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/CSS_Selectors\" target=\"_blank\" rel=\"noopener\" title=\"\">CSS selector<\/a> syntax. In the above example, we&#8217;re using <code>[]<\/code>, which means we are <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/Attribute_selectors\" target=\"_blank\" rel=\"noopener\" title=\"\">selecting HTML attribute<\/a> names. As a result, our parent component will pass two distinct templates, one for the <strong>body <\/strong>and one for the <strong>footer<\/strong>, using the following syntax:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"715\" height=\"252\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-35.png\" alt=\"\" class=\"wp-image-1117\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-35.png 715w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/06\/image-35-300x106.png 300w\" sizes=\"auto, (max-width: 715px) 100vw, 715px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>You can see an example of such <a href=\"https:\/\/stackblitz.com\/edit\/at-multi-slot-content-projection?file=src%2Fapp%2Fapp.component.html\" target=\"_blank\" rel=\"noopener\" title=\"\">code in action on Stackblitz<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yesterday, we saw that we could use content projection to pass an HTML template from one component to another. But what if we want to pass multiple different templates? We can use multi-slot content projection. Here&#8217;s what we want to achieve: In our reusable dialog component, we will have multiple ng-content elements. Each ng-content will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,21,8],"tags":[],"class_list":["post-1114","post","type-post","status-publish","format-standard","hentry","category-angular","category-architecture","category-components"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1114"}],"version-history":[{"count":2,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1114\/revisions"}],"predecessor-version":[{"id":1119,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1114\/revisions\/1119"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}