<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Adrian on Medium]]></title>
        <description><![CDATA[Stories by Adrian on Medium]]></description>
        <link>https://medium.com/@adrian_angular?source=rss-a51af819bd88------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*vyIyIIexDaIAAiax</url>
            <title>Stories by Adrian on Medium</title>
            <link>https://medium.com/@adrian_angular?source=rss-a51af819bd88------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:36:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@adrian_angular/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[New template literal features in Angular 20 ]]></title>
            <link>https://medium.com/@adrian_angular/new-template-literal-features-in-angular-20-b4943868c7d7?source=rss-a51af819bd88------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4943868c7d7</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[html-templates]]></category>
            <category><![CDATA[new-features]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Adrian]]></dc:creator>
            <pubDate>Mon, 28 Jul 2025 14:56:09 GMT</pubDate>
            <atom:updated>2025-07-28T14:56:09.264Z</atom:updated>
            <content:encoded><![CDATA[<p>The Angular team have continued to roll out more impressive updates in recent versions. They’re putting a strong emphasis on not only making Angular a feature-rich framework, but also improving the developer experience.</p><p>In Angular version 20 we now have new options for template literals which can give us greater control and more flexibility in our component templates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fmDnER6OI2UagS9WBnKL2g.jpeg" /></figure><p>Here’s a summary of what’s new ⬇️</p><h3>Exponentiation Operator</h3><p>The exponentiation (**) operator returns the result of raising the first operand to the power of the second operand. It is equivalent to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/pow">Math.pow()</a>, except it also accepts <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt">BigInts</a> as operands.</p><p>This operator can now be used directly in Angular templates, like in this example below.</p><pre>&lt;!-- Exponentiation: for dynamic sizing --&gt;<br>&lt;p&gt;2³ grid columns = {{ 2 ** 3 }}&lt;/p&gt;</pre><p>The resulting output would be:</p><pre>&lt;p&gt;2³ grid columns = 8&lt;/p&gt;</pre><h3>The in Operator</h3><p>in allows us to check for the presence of a key in a given object. This is different to checking whether the <em>value</em> of that object’s key is undefined or null .</p><p>Checking for a value that isn’t undefined would look something like this:</p><pre>@if (userInfo.email !== &#39;undefined&#39;) {<br>  &lt;p&gt;Email: {{ userInfo.email }}&lt;/p&gt;<br>}</pre><p>However, we might have a userInfo object where the email doesn’t exist at all.</p><p>Let’s say we now have a userInfo object that is a subset of a Type , where we’ve chosen to Omit the email property to avoid exposing this in a specific component.</p><h4>1. Define a property in the component</h4><p>Create a userInfo property in our component that gets our user object from the userService .</p><pre>// UserComponent<br>protected userInfo = this.userService.getUser();</pre><h4>2. The userService</h4><p>First, we need to define a type for our UserInfo — an object that holds our user data in the service.</p><p>Then, we need to create a function to get the user, with the email omitted from the object. Now when we use this object in the template, it will <strong>only</strong> have an id , firstName and lastName .</p><pre>type UserInfo = {<br>  firstName: string;<br>  email: string;<br>  lastName: string;<br>  id: number;<br>}<br><br>//UserService<br>private user: UserInfo;<br><br>public getUser(): Omit&lt;UserInfo, &#39;email&#39;&gt; {<br>  const user = {...this.user};<br>  delete user.email; // Remove email for security reasons<br><br>  return user;<br>};</pre><h4>3. Use the in operator in the template</h4><p>To handle this directly in our template, we can do the following:</p><pre>@if (&#39;email&#39; in userInfo) {<br>  &lt;p&gt;Email: {{ userInfo.email }}&lt;/p&gt;<br>}</pre><p>Now we only show anything relating to the user’s email if the userInfo object has an email property.</p><h3>Tagged template literals</h3><p>We can use untagged template literals to allow us to have greater control over using component properties in expressions to output a new string value. Here’s a simple example to explain how it works.</p><h4>1. Define a method in the Component</h4><pre>protected username: string = &#39;user123&#39;;<br>protected role: string = &#39;admin&#39;;<br><br>// TemplateStringsArray is a built-in type for the string values between the backticks `` in the template<br>// The remaining parameters are those in the template literal expression.<br>protected formatUserDetails(strings: TemplateStringsArray, username: string, role: string): string {<br>  return `${string[0]} ${username}, you have the role &quot;${role}&quot;`<br>};<br><br>// We can also use rest parameters:<br>protected formatUserDetails(strings: TemplateStringsArray, ...params: string[]): string {<br>  return `${string[0]} ${placeholders[0]}, you have the role &quot;${placeholders[1]}&quot;`<br>};</pre><h4>2. Bind in the template</h4><pre>&lt;div&gt;{{ formatUserDetails`Hello${username}${role}`}}&lt;/div&gt;</pre><h4>3. The result</h4><p>formatUserDetails would take our username and role (both are strings), and format them into a new string value.</p><p>The &quot;Hello&quot; string included at the start of the expression would still be returned since we’re using string[0] to access the first non-parameter string in the expression.</p><p>The resulting value would be:</p><pre>&lt;div&gt;Hello user123, you have the role &quot;admin&quot;&lt;/div&gt;</pre><h4>4. Additional support</h4><p>Tagged template literals also support the following:</p><pre>&lt;!-- function or method calls --&gt;<br>{{ formatUserDetails`Hello ${getUserName()}${getUserRole()}` }}<br><br>&lt;!-- string concatenation --&gt;<br>{{ formatUserDetails`Hello ${getUserName()}${getUserRole() + &#39; permission&#39;}` }}<br><br>&lt;!-- mathematical operations --&gt;<br>{{ formatUserDetails`Hello ${getUserAnnualSpend() / 12}` }}<br><br>&lt;!-- pipes --&gt;<br>{{ formatUserDetails`Hello ${getUserName()}${getUserRole() | uppercase}` }}<br><br>&lt;!-- nested tagged literals --&gt;<br>{{ formatUserDetails`Hello ${name`user123`}${getUserRole()}` }}</pre><p>For more info, there’s a great video that explains this in detail here.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F2YkGEx-ndvg%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D2YkGEx-ndvg&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F2YkGEx-ndvg%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/17ebf5560bbd97bcad2aa5f93c0ebfbd/href">https://medium.com/media/17ebf5560bbd97bcad2aa5f93c0ebfbd/href</a></iframe><h3>Untagged template literals</h3><p>An untagged template literal is more simple than a tagged template literal, in that it doesn’t have a tag name to bind it to a method in a component.</p><p>Instead, we directly use our component properties inside our templates like this example:</p><h4>1. Define a property in the component</h4><p>First we need to create a property in the component to store the user’s role.</p><pre>public userRole: &#39;admin&#39; | &#39;contributor&#39; | &#39;editor&#39; | &#39;user&#39; = this.getUserRole();</pre><h4>2. Bind that property in a template expression</h4><p>Use the userRole property in our untagged template literal.</p><pre>&lt;div [class]=&quot;`user-details role-${userRole}`&quot;&gt;{{ userRole }}&lt;/div&gt;</pre><p>An alternative to this would be to define classes based on the user role. Using untagged template literals can therefore be quite beneficial in examples like this.</p><pre>&lt;!-- Not using untagged template literals --&gt;<br>&lt;div [class]=&quot;`user-details&quot;<br>  [class.role-admin]=&quot;userRole === &#39;admin&#39;&quot;<br>  [class.role-contributor]=&quot;userRole === &#39;contributor&#39;&quot;<br>  [class.role-editor]=&quot;userRole === &#39;editor&#39;&quot;<br>  [class.role-user]=&quot;userRole === &#39;user&#39;&quot;&gt;<br>  {{ userRole }}<br>&lt;/div&gt;</pre><h4>3. Define CSS classes for each of the user roles</h4><p>Here we can define different CSS classes to apply a different colour to the text based on the role name.</p><pre>.user-details {<br>  padding: 10px;<br><br>  &amp;.role-admin {<br>    color: red;<br>  }<br><br>  &amp;.role-contributor {<br>    color: blue;<br>  }<br><br>  &amp;.role-editor {<br>    color: green;<br>  }<br><br>  &amp;.role-user {<br>    color: black;<br>  }<br>}</pre><h4>Conclusion</h4><p>There are far more features included in Angular 20, but hopefully this helps to explain some of the new template literal features and how they can be used in your Angular application.</p><p>Thanks for reading. Be sure to follow for more useful Angular content!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4943868c7d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>