{"id":26407,"date":"2024-03-12T15:44:28","date_gmt":"2024-03-12T14:44:28","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/?p=26407"},"modified":"2024-03-12T15:47:25","modified_gmt":"2024-03-12T14:47:25","slug":"angular-signal-queries-simplifying-dom-querying","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/","title":{"rendered":"Angular Signal Queries: simplifying DOM querying"},"content":{"rendered":"\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><\/p>\n\n\n\n<p>Following <strong><a aria-label=\"Signal Input (opens in a new tab)\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-inputs\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">Signal Inputs<\/a><\/strong> and <strong><a aria-label=\"Model Inputs (opens in a new tab)\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-model-inputs-two-way-binding-inputs-with-signals\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">Model Inputs<\/a><\/strong>, another <strong>Signal<\/strong> API has landed in the Angular ecosystem with the release of v17.2.0: <strong>Signal Queries<\/strong>.<\/p>\n\n\n\n<p><strong>Signal Queries<\/strong> offer an alternative approach to the decorator-based queries, namely <code><strong>@ViewChild<\/strong><\/code>, <code><strong>@ViewChildren<\/strong><\/code>, <code><strong>@ContentChild<\/strong><\/code> and <code><strong>@ContentChildren<\/strong><\/code><strong>, <\/strong>supplying query results as a <strong>Signal<\/strong>.<\/p>\n\n\n\n<p>With queries you can retrieve references to components, directives, DOM elements, and more. Let\u2019s see what has changed with <strong>Signal Queries.<\/strong><\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"has-text-align-center\">\u26a0\ufe0f <strong>ALERT:<\/strong> new <strong>Signal Queries <\/strong>are still in developer preview \u26a0\ufe0f<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-view-queries\">View queries<\/h2>\n\n\n\n<p>View queries allow you to retrieve and interact directly with elements in a component\u2019s own template, also known as <strong>view<\/strong>.<\/p>\n\n\n\n<p>Both <code><strong>@ViewChild<\/strong><\/code> and <code><strong>@ViewChildren<\/strong><\/code> now have a <strong>Signal<\/strong> counterpart.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*bFt3_b0TBvYzpRFVqxB7pQ.png\" alt=\"\" style=\"aspect-ratio:3.007518796992481;object-fit:cover;width:550px\"\/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-viewchild\">viewChild<\/h3>\n\n\n\n<p>Using the new <code><strong>viewChild<\/strong><\/code> function you can retrieve a single element:<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\"><pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"TypeScript\" data-shcb-language-slug=\"typescript\"><span><code class=\"hljs language-typescript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> { Component, ElementRef, Signal, viewChild } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@angular\/core'<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-meta\">@Component<\/span>({\n<\/span><\/span><span class='shcb-loc'><span>  selector: <span class=\"hljs-string\">'my-component'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  standalone: <span class=\"hljs-literal\">true<\/span>,\n<\/span><\/span><mark class='shcb-loc'><span>  template: <span class=\"hljs-string\">'&lt;input #inputEl \/&gt;'<\/span>,\n<\/span><\/mark><span class='shcb-loc'><span>})\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> MyComponent {\n<\/span><\/span><mark class='shcb-loc'><span>  inputElement: Signal&lt;ElementRef | <span class=\"hljs-literal\">undefined<\/span>&gt; = viewChild(<span class=\"hljs-string\">'inputEl'<\/span>);\n<\/span><\/mark><span class='shcb-loc'><span>}\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">TypeScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">typescript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre><\/div><\/div>\n\n\n\n<p>This function accepts every parameter that <code><strong>@ViewChild<\/strong><\/code> supports and offers the same functionalities, providing you deliver the query result as a <strong>Signal<\/strong>.<\/p>\n\n\n\n<p>When a query does not find any result its value is <code><strong>undefined<\/strong><\/code>, this happens commonly using <strong><a href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-control-flow-the-complete-guide\/\" target=\"_blank\" aria-label=\"Control Flow (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Control Flow<\/a><\/strong> statement like <code><strong>@if<\/strong><\/code> and <code><strong>@for<\/strong><\/code>.&nbsp;<br>Because of this, a <code><strong>viewChild<\/strong><\/code> <strong>Signal<\/strong> value type is <code><strong>ElementRef | undefined<\/strong><\/code>.<\/p>\n\n\n\n<p>If you are sure about the presence of at least one matching result, you can use the dedicated <code><strong>viewChild.required()<\/strong><\/code> function and get rid of <code><strong>undefined<\/strong><\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"TypeScript\" data-shcb-language-slug=\"typescript\"><span><code class=\"hljs language-typescript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> { Component, ElementRef, Signal, viewChild } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@angular\/core'<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-meta\">@Component<\/span>({\n<\/span><\/span><span class='shcb-loc'><span>  selector: <span class=\"hljs-string\">'my-component'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  standalone: <span class=\"hljs-literal\">true<\/span>,\n<\/span><\/span><mark class='shcb-loc'><span>  template: <span class=\"hljs-string\">'&lt;input #inputEl \/&gt;'<\/span>,\n<\/span><\/mark><span class='shcb-loc'><span>})\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> MyComponent {\n<\/span><\/span><mark class='shcb-loc'><span>  inputElement: Signal&lt;ElementRef&gt; = viewChild.required(<span class=\"hljs-string\">'inputEl'<\/span>);\n<\/span><\/mark><span class='shcb-loc'><span>}\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">TypeScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">typescript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>But be careful, when a <strong>required<\/strong> query fails to find any results, <strong>Angular<\/strong> throws a dedicated <strong>error:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*4HWdoe-UAgN4Uy8KmYt6Mw.png\" alt=\"\" style=\"width:650px\"\/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-viewchildren\">viewChildren<\/h3>\n\n\n\n<p>Using the new <code><strong>viewChildren<\/strong><\/code> function you can retrieve multiple elements:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"TypeScript\" data-shcb-language-slug=\"typescript\"><span><code class=\"hljs language-typescript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> { Component, ElementRef, Signal, viewChildren } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@angular\/core'<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-meta\">@Component<\/span>({\n<\/span><\/span><span class='shcb-loc'><span>  selector: <span class=\"hljs-string\">'my-component'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  standalone: <span class=\"hljs-literal\">true<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  template: <span class=\"hljs-string\">`<\/span>\n<\/span><\/span><mark class='shcb-loc'><span><span class=\"hljs-string\">    &lt;input #inputEl \/&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span><span class=\"hljs-string\"><\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-string\">    @if (showSecondInput) {<\/span>\n<\/span><\/span><mark class='shcb-loc'><span><span class=\"hljs-string\">      &lt;input #inputEl \/&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span><span class=\"hljs-string\">    }<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-string\">  `<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>})\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> MyComponent {\n<\/span><\/span><span class='shcb-loc'><span>  showSecondInput = <span class=\"hljs-literal\">true<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><mark class='shcb-loc'><span>  inputElementList: Signal&lt;readonly ElementRef&#91;]&gt; = viewChildren(<span class=\"hljs-string\">'inputEl'<\/span>);\n<\/span><\/mark><span class='shcb-loc'><span>}\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">TypeScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">typescript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Similarly to <code><strong>viewChild<\/strong><\/code> API, the <code><strong>viewChildren<\/strong><\/code> function accepts every parameter that <code><strong>@ViewChildren<\/strong><\/code> supports and offers the same functionalities, providing you the query result as a <strong>Signal<\/strong>.<\/p>\n\n\n\n<p>When a <code><strong>viewChildren<\/strong><\/code><strong> <\/strong>query does not find any result, its value is an <strong>empty array<\/strong>, this guarantees the results array to be always initialized.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-content-queries\">Content queries<\/h2>\n\n\n\n<p>Content queries allow you to retrieve and interact directly with elements in a component\u2019s content.<\/p>\n\n\n\n<p>A component\u2019s content is represented by the elements provided through <strong>content projection<\/strong>, nesting elements inside the component tag in the template where it is used. For example:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">my-component<\/span>&gt;<\/span>\n<\/span><\/span><mark class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">span<\/span>&gt;<\/span> Hello ;) <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">span<\/span>&gt;<\/span>\n<\/span><\/mark><mark class='shcb-loc'><span>\n<\/span><\/mark><mark class='shcb-loc'><span>  <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">input<\/span> #<span class=\"hljs-attr\">inputEl<\/span> \/&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">my-component<\/span>&gt;<\/span>\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><\/p>\n\n\n\n<p><strong>Note: <\/strong>apart for the target template where the queries are performed, <strong>content queries<\/strong> APIs and <strong>view queries<\/strong> APIs work identically.<br>Because of that the next section of the article totally relies on the previous one.<\/p>\n\n\n\n<p><\/p>\n<\/blockquote>\n\n\n\n<p>Similarily to our previous discussion on view queries, both <code><strong>@ContentChild<\/strong><\/code> and <code><strong>@ContentChildren<\/strong><\/code> now have as well a <strong>Signal<\/strong> counterpart.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*SViw3XEaqL_GntvhnDMZ2Q.png\" alt=\"\" style=\"aspect-ratio:3.007518796992481;width:550px;height:auto\"\/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-contentchild\">contentChild<\/h3>\n\n\n\n<p>Using the new <code><strong>contentChild<\/strong><\/code> and <code><strong>contentChild.required()<\/strong><\/code> functions you can retrieve a single element:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"TypeScript\" data-shcb-language-slug=\"typescript\"><span><code class=\"hljs language-typescript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> { Component, contentChild, ElementRef, Signal } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@angular\/core'<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-meta\">@Component<\/span>({\n<\/span><\/span><span class='shcb-loc'><span>  selector: <span class=\"hljs-string\">'my-component'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  standalone: <span class=\"hljs-literal\">true<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  template: <span class=\"hljs-string\">`<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-string\">    &lt;div&gt;<\/span>\n<\/span><\/span><mark class='shcb-loc'><span><span class=\"hljs-string\">      &lt;ng-content \/&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span><span class=\"hljs-string\">    &lt;\/div&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-string\">  `<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>})\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> MyComponent {\n<\/span><\/span><mark class='shcb-loc'><span>  inputElement: Signal&lt;ElementRef | <span class=\"hljs-literal\">undefined<\/span>&gt; = contentChild(<span class=\"hljs-string\">'inputEl'<\/span>);\n<\/span><\/mark><span class='shcb-loc'><span>\n<\/span><\/span><mark class='shcb-loc'><span>  inputElementReq: Signal&lt;ElementRef&gt; = contentChild.required(<span class=\"hljs-string\">'inputEl'<\/span>);\n<\/span><\/mark><span class='shcb-loc'><span>}\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">TypeScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">typescript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Identically to the <code><strong>viewChild<\/strong><\/code> function, when a <strong>required<\/strong> <code><strong>contentChild<\/strong><\/code> function query fails to find any results, <strong>Angular<\/strong> throws a dedicated <strong>error:<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img decoding=\"async\" src=\"https:\/\/cdn-images-1.medium.com\/max\/1600\/1*m6ktMplGCrKmstq3zw3kxQ.png\" alt=\"\" style=\"aspect-ratio:3.911764705882353;object-fit:cover;width:650px\"\/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"h-contentchildren\">contentChildren<\/h3>\n\n\n\n<p>Using the <code><strong>contentChildren<\/strong><\/code> function you can retrieve multiple elements:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"TypeScript\" data-shcb-language-slug=\"typescript\"><span><code class=\"hljs language-typescript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> { Component, contentChildren, ElementRef, Signal } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@angular\/core'<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-meta\">@Component<\/span>({\n<\/span><\/span><span class='shcb-loc'><span>  selector: <span class=\"hljs-string\">'my-component'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  standalone: <span class=\"hljs-literal\">true<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  template: <span class=\"hljs-string\">`<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-string\">    &lt;div&gt;<\/span>\n<\/span><\/span><mark class='shcb-loc'><span><span class=\"hljs-string\">      &lt;ng-content \/&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span><span class=\"hljs-string\">    &lt;\/div&gt;<\/span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-string\">  `<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>})\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> MyComponent {\n<\/span><\/span><mark class='shcb-loc'><span>  inputElementList: Signal&lt;readonly ElementRef&#91;]&gt; = contentChildren(<span class=\"hljs-string\">'inputEl'<\/span>);\n<\/span><\/mark><span class='shcb-loc'><span>}\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">TypeScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">typescript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Identically to the <code><strong>viewChildren<\/strong><\/code> function, when a <code><strong>contentChildren<\/strong><\/code><strong> <\/strong>query does not find any result, its value is an <strong>empty array<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-some-rules-you-need-to-be-nbsp-careful\">Some rules you need to be&nbsp;careful<\/h2>\n\n\n\n<p>These new functions, <code><strong>viewChild<\/strong><\/code>, <code><strong>viewChildren<\/strong><\/code>, <code><strong>contentChild<\/strong><\/code> and <code><strong>contentChildren<\/strong><\/code>, only work if used to declare queries by initializing a component or a directive property.<\/p>\n\n\n\n<p>Calling them outside of component and directive property initialization will produce no error, but the query will not find any result:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"TypeScript\" data-shcb-language-slug=\"typescript\"><span><code class=\"hljs language-typescript shcb-code-table shcb-line-numbers\"><span class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> { Component, ElementRef, Signal, viewChild } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'@angular\/core'<\/span>;\n<\/span><\/span><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-meta\">@Component<\/span>({\n<\/span><\/span><span class='shcb-loc'><span>  selector: <span class=\"hljs-string\">'my-component'<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  standalone: <span class=\"hljs-literal\">true<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>  template: <span class=\"hljs-string\">`<\/span>\n<\/span><\/span><mark class='shcb-loc'><span><span class=\"hljs-string\">    &lt;div #el&gt;&lt;\/div&gt;<\/span>\n<\/span><\/mark><span class='shcb-loc'><span><span class=\"hljs-string\">  `<\/span>,\n<\/span><\/span><span class='shcb-loc'><span>})\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">class<\/span> MyComponent {\n<\/span><\/span><mark class='shcb-loc'><span>  el = viewChild(<span class=\"hljs-string\">'el'<\/span>); <span class=\"hljs-comment\">\/\/ It works!<\/span>\n<\/span><\/mark><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-keyword\">constructor<\/span>(<span class=\"hljs-params\"><\/span>) {\n<\/span><\/span><mark class='shcb-loc'><span>    <span class=\"hljs-keyword\">const<\/span> myEl: Signal&lt;<span class=\"hljs-literal\">undefined<\/span>&gt; = viewChild(<span class=\"hljs-string\">'el'<\/span>); <span class=\"hljs-comment\">\/\/ No error<\/span>\n<\/span><\/mark><mark class='shcb-loc'><span>    <span class=\"hljs-built_in\">console<\/span>.log(myEl()); <span class=\"hljs-comment\">\/\/ undefined<\/span>\n<\/span><\/mark><span class='shcb-loc'><span>  }\n<\/span><\/span><span class='shcb-loc'><span>}\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">TypeScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">typescript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-signal-queries-vs-decorator-queries\">Signal Queries vs Decorator Queries<\/h2>\n\n\n\n<p>Having the query results as <strong>Signals<\/strong> means that we can compose them with other <strong>Signals<\/strong>, using <code><strong>computed<\/strong><\/code> and <code><strong>effect<\/strong><\/code> functions.<\/p>\n\n\n\n<p>This is a significant advantage, as it enhances the flexibility and functionality of our codebase, leading the way to all the improvements in change detection that <strong>Signals<\/strong> brought to the framework.<\/p>\n\n\n\n<p>In addition to that, <strong>Signal Queries<\/strong> offer other benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>More predictable timing<\/strong>: query results are accessible as soon as they\u2019re available;<\/li>\n\n\n\n<li><strong>Simpler API surface<\/strong>: every query result is provided as a <strong>Signal<\/strong>, and queries with multiple results (<code><strong>viewChildren<\/strong><\/code> and <code><strong>contentChildren<\/strong><\/code>) return always a defined array;<\/li>\n\n\n\n<li><strong>Improved type safety<\/strong>: cases with <code><strong>undefined<\/strong><\/code><strong> <\/strong>as possible result are fewer, thanks to <code><strong>required()<\/strong><\/code> functions and default array for multiple results;<\/li>\n\n\n\n<li><strong>More accurate type inference<\/strong>: TypeScript can infer more accurate types when a type predicate is used or when you specify a <code><strong>read<\/strong><\/code> option;<\/li>\n\n\n\n<li><strong>Lazier updates<\/strong>: as for all <strong>Signals<\/strong>, Angular updates query results lazily. This means that the read operation is performed only when your code explicitly reads the query results.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-dots\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-thanks-for-reading-so-far-nbsp\">Thanks for reading so far&nbsp;\ud83d\ude4f<\/h2>\n\n\n\n<p>I\u2019d like to have your feedback so please feel free to contact me for any. \ud83d\udc4b<\/p>\n\n\n\n<p>Then, if you really liked it, <strong>share it<\/strong> among your community, tech bros and whoever you want. \ud83d\udc4b\ud83d\ude01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Following Signal Inputs and Model Inputs, another Signal API has landed in the Angular ecosystem with the release of v17.2.0: Signal Queries. Signal Queries offer an alternative approach to the decorator-based queries, namely @ViewChild, @ViewChildren, @ContentChild and @ContentChildren, supplying query results as a Signal. With queries you can retrieve references to components, directives, DOM elements,&#8230; <a class=\"more-link\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\">Read more<\/a><\/p>\n","protected":false},"author":200,"featured_media":26468,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[6],"tags":[],"collections":[],"class_list":{"0":"post-26407","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-frontend","8":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Angular Signal Queries: simplifying DOM querying - Codemotion Magazine<\/title>\n<meta name=\"description\" content=\"Angular Signal Queries offer an alternative to @ViewChild, @ViewChildren, @ContentChild and @ContentChildren. Let\u2019s see what has changed.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Angular Signal Queries: simplifying DOM querying\" \/>\n<meta property=\"og:description\" content=\"Angular Signal Queries offer an alternative to @ViewChild, @ViewChildren, @ContentChild and @ContentChildren. Let\u2019s see what has changed.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-12T14:44:28+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-12T14:47:25+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1820\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Davide Passafaro\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Davide Passafaro\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\"},\"author\":{\"name\":\"Davide Passafaro\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/79170e2a1bfc41ddeaa10827ce803828\"},\"headline\":\"Angular Signal Queries: simplifying DOM querying\",\"datePublished\":\"2024-03-12T14:44:28+00:00\",\"dateModified\":\"2024-03-12T14:47:25+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\"},\"wordCount\":674,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png\",\"articleSection\":[\"Frontend\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\",\"name\":\"Angular Signal Queries: simplifying DOM querying - Codemotion Magazine\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png\",\"datePublished\":\"2024-03-12T14:44:28+00:00\",\"dateModified\":\"2024-03-12T14:47:25+00:00\",\"description\":\"Angular Signal Queries offer an alternative to @ViewChild, @ViewChildren, @ContentChild and @ContentChildren. Let\u2019s see what has changed.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png\",\"width\":1820,\"height\":1024,\"caption\":\"Angular Signal Queries\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Frontend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/frontend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Angular Signal Queries: simplifying DOM querying\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/79170e2a1bfc41ddeaa10827ce803828\",\"name\":\"Davide Passafaro\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/11\/Davide-photo-1mb-100x100.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/11\/Davide-photo-1mb-100x100.png\",\"caption\":\"Davide Passafaro\"},\"description\":\"My name is Davide Passafaro and I am Senior Frontend Engineer at Awork. I lead two developer communities in Rome, GDG Roma Citt\u00e0 and Angular Rome, and actively contribute to the tech community as a writer and speaker. When i shut down my computer I like to play board games and archery, not both together till now. I also like escape rooms and memes.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/davide-passafaro\/\"],\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/davidepassafaro\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Angular Signal Queries: simplifying DOM querying - Codemotion Magazine","description":"Angular Signal Queries offer an alternative to @ViewChild, @ViewChildren, @ContentChild and @ContentChildren. Let\u2019s see what has changed.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/","og_locale":"en_US","og_type":"article","og_title":"Angular Signal Queries: simplifying DOM querying","og_description":"Angular Signal Queries offer an alternative to @ViewChild, @ViewChildren, @ContentChild and @ContentChildren. Let\u2019s see what has changed.","og_url":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_published_time":"2024-03-12T14:44:28+00:00","article_modified_time":"2024-03-12T14:47:25+00:00","og_image":[{"width":1820,"height":1024,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png","type":"image\/png"}],"author":"Davide Passafaro","twitter_card":"summary_large_image","twitter_creator":"@CodemotionIT","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Davide Passafaro","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/"},"author":{"name":"Davide Passafaro","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/79170e2a1bfc41ddeaa10827ce803828"},"headline":"Angular Signal Queries: simplifying DOM querying","datePublished":"2024-03-12T14:44:28+00:00","dateModified":"2024-03-12T14:47:25+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/"},"wordCount":674,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png","articleSection":["Frontend"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/","url":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/","name":"Angular Signal Queries: simplifying DOM querying - Codemotion Magazine","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png","datePublished":"2024-03-12T14:44:28+00:00","dateModified":"2024-03-12T14:47:25+00:00","description":"Angular Signal Queries offer an alternative to @ViewChild, @ViewChildren, @ContentChild and @ContentChildren. Let\u2019s see what has changed.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png","width":1820,"height":1024,"caption":"Angular Signal Queries"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/frontend\/angular-signal-queries-simplifying-dom-querying\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Frontend","item":"https:\/\/www.codemotion.com\/magazine\/frontend\/"},{"@type":"ListItem","position":3,"name":"Angular Signal Queries: simplifying DOM querying"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/79170e2a1bfc41ddeaa10827ce803828","name":"Davide Passafaro","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/11\/Davide-photo-1mb-100x100.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/11\/Davide-photo-1mb-100x100.png","caption":"Davide Passafaro"},"description":"My name is Davide Passafaro and I am Senior Frontend Engineer at Awork. I lead two developer communities in Rome, GDG Roma Citt\u00e0 and Angular Rome, and actively contribute to the tech community as a writer and speaker. When i shut down my computer I like to play board games and archery, not both together till now. I also like escape rooms and memes.","sameAs":["https:\/\/www.linkedin.com\/in\/davide-passafaro\/"],"url":"https:\/\/www.codemotion.com\/magazine\/author\/davidepassafaro\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-600x400.png","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-600x600.png","author_info":{"display_name":"Davide Passafaro","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/davidepassafaro\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png",1820,1024,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-150x150.png",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-300x169.png",300,169,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-768x432.png",768,432,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-1024x576.png",1024,576,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-1536x864.png",1536,864,true],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10.png",1820,1024,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-100x100.png",100,100,true],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-180x128.png",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-896x504.png",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-400x225.png",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-600x400.png",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2024\/03\/image-10-600x600.png",600,600,true]},"uagb_author_info":{"display_name":"Davide Passafaro","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/davidepassafaro\/"},"uagb_comment_info":0,"uagb_excerpt":"Following Signal Inputs and Model Inputs, another Signal API has landed in the Angular ecosystem with the release of v17.2.0: Signal Queries. Signal Queries offer an alternative approach to the decorator-based queries, namely @ViewChild, @ViewChildren, @ContentChild and @ContentChildren, supplying query results as a Signal. With queries you can retrieve references to components, directives, DOM elements,&#8230;&hellip;","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/26407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/200"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=26407"}],"version-history":[{"count":2,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/26407\/revisions"}],"predecessor-version":[{"id":26471,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/26407\/revisions\/26471"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/26468"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=26407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=26407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=26407"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=26407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}