<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
	<channel>
		<title>Author at Infinum</title>
		<atom:link href="https://infinum.com/blog/author/dani-pavic/feed/" rel="self" type="application/rss+xml" />
		<link></link>
		<description>Building digital products</description>
		<lastBuildDate>Thu, 23 Apr 2026 13:14:19 +0000</lastBuildDate>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>

					<item>
				<image>
					<url>19256684https://infinum.com/uploads/2024/08/Angular-typed-forms-min.webp</url>
				</image>
				<title>Type Smarter, Not Harder – Get the Most of Angular Typed Forms</title>
				<link>https://infinum.com/blog/angular-typed-forms/</link>
				<pubDate>Wed, 14 Aug 2024 10:37:45 +0000</pubDate>
				<dc:creator>Đani Pavić</dc:creator>
				<guid isPermaLink="false">https://infinum.com/?p=19256684</guid>
				<description>
					<![CDATA[<p>Explore our expert guide on Angular Typed Forms, packed with best practices to optimize Angular’s key feature in your projects.</p>
<p>The post <a href="https://infinum.com/blog/angular-typed-forms/">Type Smarter, Not Harder – Get the Most of Angular Typed Forms</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</description>
				<content:encoded>
					<![CDATA[<div
	class="wrapper"
	data-id="es-296"
	 data-animation-target='inner-items'>
		
			<div class="wrapper__inner">
			<div class="block-blog-content js-block-blog-content">
	
<div class="block-blog-content-sidebar" data-id="es-92">
	</div>

<div class="block-blog-content-main">
	
<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-95"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-93">
	<p	class='typography typography--size-36-text js-typography block-paragraph__paragraph'
	data-id='es-94'
	>
	<strong>Drawing on our on-the-ground experience with Angular Typed Forms, we present a thorough guide coupled with best practices, enabling you to make the most of Angular’s stellar feature in your everyday projects.</strong></p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-98"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-96">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-97'
	>
	Angular Typed Forms, one of the more recent and certainly the most significant enhancements to the Reactive Forms API, enable you to – add types to your Angular forms. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-101"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-99">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-100'
	>
	Initially introduced as a developer preview in Angular 14, Angular Typed Forms have been deemed stable as of Angular 15. This particular form type helps us catch errors early in development, enhances code readability and maintainability, and supports useful features like auto-completion.&nbsp;</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-104"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-102">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-103'
	>
	The feature, which was <a href="https://github.com/angular/angular/issues/13721" target="_blank" rel="noreferrer noopener">the top-requested enhancement</a> for several years, was finally implemented by the Angular team in response to community feedback. As Angular Typed Forms have matured, our team at Infinum has accumulated ample practical experience in their use. In this article, we aim to share what we have learned and bring you practical recommendations and proven best practices so you can make the most of Angular’s prized feature. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-111"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<a	class="card-simple js-card-simple card-simple--is-ad block-card__card-simple card-simple--has-link js-card-simple-link card-simple__content-align--left"
	data-id="es-105"
	 target='_blank' rel='noopener noreferrer' href='https://infinum.com/blog/introducing-angular-signals/'>

	
	
	<div class="card-simple__content">
		<div class="card-simple__heading-wrap">
			<h2	class='typography typography--size-24-text js-typography card-simple__heading'
	data-id='es-106'
	>
	<strong><strong>As you dive into the intricacies of Angular Typed Forms, don’t miss out on how Angular Signals can take your apps to the next level. Check out what we’ve written about the feature many are calling the framework’s renaissance.</strong></strong></h2>		</div>

		<button	class="btn btn--color-infinum btn--size-small btn--width-default btn__icon-position--right card-simple__btn js-block-card-btn js-card-simple-link"
	data-id="es-108"
	 tabindex='-1'>
		<div class="btn__inner">
					<div	class='typography typography--size-none js-typography btn__label'
	data-id='es-109'
	>
	Read the article </div>		
		<i
	class="icon btn__icon icon--size-16 icon--scale-100"
	 aria-hidden='true' data-name='arrow-right-16' data-id='es-110'>
	<svg fill='none' height='16' viewBox='0 0 17 16' width='17' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'><g stroke='currentColor' stroke-width='2'><path d='m.5 7.99999 14 .00001'/><path d='m9.23352 2.7251 5.97848 5.97852'/><path d='m9.23352 13.2744 5.97848-5.9785'/></g></svg></i>	</div>
	</button>	</div>
</a>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-114"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-112">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-113'
	>
	What Angular Typed Forms do and don’t do</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-117"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-115">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-116'
	>
	The main goal of typed forms is to maximize type safety and enhance the developer experience in creating Reactive Forms. The Angular team wanted to support their gradual adoption, so they enabled the use of both typed and untyped forms to prevent disrupting existing applications.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-120"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-118">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-119'
	>
	Angular Typed Forms are not designed to support template-driven forms or non-model classes such as validators. They are also not intended to alter the underlying functionality of forms; all current form APIs remain the same.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-123"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-121">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-122'
	>
	From untyped to typed – the evolution of Angular forms</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-126"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-124">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-125'
	>
	Let’s explore how <code>FormGroup</code> and <code>FormControl</code>, key components of Angular&#8217;s reactive forms, are used in versions before Angular 14 and in version 14 and beyond.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-129"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-127">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-128'
	>
	Consider the following simple code using <code>FormGroup</code> with one <code>FormControl</code>:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-131"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">readonly</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleFormGroup</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormGroup</span><span class="token">(</span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlOne</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleOne</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Template</span><span class="token">
</span></span><span class="line"><span class="token">&lt;</span><span class="token" style="color: #22863a;">input</span><span class="token"> </span><span class="token" style="color: #6f42c1;">type</span><span class="token" style="color: #d73a49;">=</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">text</span><span class="token" style="color: #032f62;">&quot;</span><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">[formControl]=&quot;exampleFormGroup.controls.exampleControlTwo&quot;</span><span class="token"> </span><span class="token">/&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-134"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-132">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-133'
	>
	In versions preceding Angular 14, you could write this kind of code without knowing if the control exists inside the <code>FormGroup</code>. This example is obvious, but it could have easily happened that you made a tiny typo and spent quite a lot of time debugging. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-137"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-135">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-136'
	>
	With typed forms, you get the following error:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-139"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Property &#039;exampleControlTwo&#039; does not exist on type &#039;{ exampleControlOne: FormControl&lt;string | null&gt;; }&#039;.</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-142"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-140">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-141'
	>
	On top of getting an error message, you are less likely to make this type of error in the first place because the autocomplete feature will give you a list of all of the controls.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-145"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-143">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-144'
	>
	Another big improvement Angular Typed Forms brings is in the usage of <code>FormControl</code> values. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-148"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-146">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-147'
	>
	Let’s say a child component has an input that accepts a value of some type; for example, <code>string</code>, and we want to pass our <code>FormControl</code> value. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-150"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleControlOne</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #005cc5;">true</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;">Template</span><span class="token">
</span></span><span class="line"><span class="token">&lt;</span><span class="token" style="color: #005cc5;">app-child</span><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">[exampleStringInput]=&quot;exampleControlOne.value&quot;&gt;&lt;/app-child&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-153"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-151">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-152'
	>
	In this example, you might get runtime errors but won’t get build-time errors, even though we passed a <code>boolean</code> value to a <code>string</code> input. In the Angular versions below 14, all <code>FormControl</code> values are typed as <code>any</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-156"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-154">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-155'
	>
	This is what happens with typed forms:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-158"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleControlOne</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #005cc5;">true</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;">Template</span><span class="token">
</span></span><span class="line"><span class="token">&lt;</span><span class="token" style="color: #005cc5;">app-child</span><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">[exampleStringInput]=&quot;exampleControlOne.value&quot;&gt;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #b31d28;font-style: italic;">&lt;/app-child&gt;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Type &#039;boolean&#039; is not assignable to type &#039;string&#039;.</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-161"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-159">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-160'
	>
	We get a pretty obvious TypeScript error, which is a huge win.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-164"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-162">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-163'
	>
	FormControl</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-167"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-165">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-166'
	>
	In Angular 14 and beyond, form controls are typed by default. You don’t have to do anything special to create your first typed <code>FormControl</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-169"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleControlTwo</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> FormTestComponent.exampleControlTwo: FormControl&lt;string | null&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-172"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-170">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-171'
	>
	The type resulting from the above control is <code>FormControl&lt;string | null&gt;</code>. Angular automatically infers the control type from the initial value.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-175"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-173">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-174'
	>
	What if our control value can be of multiple types, for example, a number and a string? In this case, Angular cannot know all the possible value types, so we need to supply them as a Typescript generic argument to <code>FormControl</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-177"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleControlTwo</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">&lt;</span><span class="token" style="color: #005cc5;">string</span><span class="token"> </span><span class="token" style="color: #d73a49;">|</span><span class="token"> </span><span class="token" style="color: #005cc5;">number</span><span class="token">&gt;</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> FormTestComponent.exampleControlTwo: &lt;string | number | null&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-180"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-178">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-179'
	>
	Now, why does <code>null</code> appear in the list if we said the <code>FormControl</code> type is either <code>string</code> or <code>number</code>?<br />
<br />
Every typed <code>FormControl</code> can be <code>null</code> by default, i.e., they are nullable. This happens because every <code>FormControl</code> can be reset, and if you call the <code>.reset()</code> method, it will set the value to <code>null</code>, so the type is indeed correct. However, if this is not a desired behavior for your use case, you can change it by passing a <code>nonNullable</code> flag as an option to <code>FormControl</code>. With the flag set to <code>true</code>, the <code>FormControl</code> will reset to the initial value instead of <code>null</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-182"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token"> </span><span class="token" style="color: #22863a;">&lt;e</span><span class="token">m</span><span class="token">&gt;</span><span class="token">private</span><span class="token">&lt;</span><span class="token" style="color: #22863a;">/e</span><span class="token">m</span><span class="token">&gt;</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleControlTwo</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">,</span><span class="token"> </span><span class="token">{</span><span class="token">nonNullable</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">true</span><span class="token">}</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> FormTestComponent.exampleControlTwo: FormControl&lt;string&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-185"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-183">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-184'
	>
	What if you do not supply the initial value and a generic argument?</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-187"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token"> </span><span class="token" style="color: #22863a;">&lt;e</span><span class="token">m</span><span class="token">&gt;</span><span class="token">private</span><span class="token">&lt;</span><span class="token" style="color: #22863a;">/e</span><span class="token">m</span><span class="token">&gt;</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleControlTwo</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> FormTestComponent.exampleControlTwo: FormControl&lt;any&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-190"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-188">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-189'
	>
	The resulting type will be <code>FormControl&lt;any&gt;</code>. This is because we didn’t supply any type information or initial value to <code>FormControl</code>, and Angular can’t infer it.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-193"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-191">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-192'
	>
	In most cases, Angular will infer the type of <code>FormControl</code> correctly by default. We prefer this approach over stating the types explicitly unless we really need them.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-196"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-194">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-195'
	>
	FormArray</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-199"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-197">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-198'
	>
	The inferred <code>FormArray</code> type will be the result of all its inner control types. If you want to have different types of controls inside the array, you must use <code>UntypedFormArray</code>. They are created in the same way, and everything said in the <code>FormControl</code> section applies to <code>FormArray</code> as well.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-201"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleFormArray</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormArray</span><span class="token">(</span><span class="token">[</span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">]</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> FormTestComponent.exampleFormArray: FormArray&lt;FormControl&lt;string | null&gt;&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-204"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-202">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-203'
	>
	FormGroup</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-207"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-205">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-206'
	>
	<code>FormGroup</code> behaves the same as in previous Angular versions, the only exception being the difference between <code>value</code> and <code>rawValue</code> explained later on.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-210"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-208">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-209'
	>
	Note: It is possible to mix and match typed and untyped form controls in the typed <code>FormGroup</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-212"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleFormGroup</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormGroup</span><span class="token">(</span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControl</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> FormTestComponent.exampleFormGroup: FormGroup&lt;{</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;">   exampleControl: FormControl&lt;string | null&gt;;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> }&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-215"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-213">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-214'
	>
	FormBuilder</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-218"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-216">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-217'
	>
	<code>FormBuilder</code> also got an upgrade in the form of typed support. All the rules explained above apply to <code>FormBuilder</code> as well. If you want to create a form with all the controls set as non-nullable, just use the <code>NonNullableFormBuilder</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-221"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-219">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-220'
	>
	Form value and rawValue types</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-224"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-222">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-223'
	>
	Angular has no built-in utility type for inferring the type of value property nor a <code>getRawValue</code> method. Because we needed one of those, we created a utility type that you can also use. The helpers are part of the <a href="https://infinum.github.io/ngx-nuts-and-bolts/docs/form-utils" target="_blank" rel="noreferrer noopener">ngx-nuts-and-bolts package</a> on the NPM.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-227"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-225">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-226'
	>
	To extract a form value or a raw value as a type and use it in multiple places within a project, we need to follow two simple steps.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-231"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="bullet bullet--left bullet__type--number bullet__color--infinum block-bullet__bullet" data-id="es-228">
	<p	class='typography typography--size-14-text js-typography bullet__dot'
	data-id='es-229'
	>
	1</p>	<div class="bullet__content">
		<p	class='typography typography--size-20-text-roman js-typography bullet__paragraph'
	data-id='es-230'
	>
	Create a helper function that will return <code>FormGroup</code>, <code>FormControl</code>, etc.</p>	</div>
</div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-235"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="bullet bullet--left bullet__type--number bullet__color--infinum block-bullet__bullet" data-id="es-232">
	<p	class='typography typography--size-14-text js-typography bullet__dot'
	data-id='es-233'
	>
	2</p>	<div class="bullet__content">
		<p	class='typography typography--size-20-text-roman js-typography bullet__paragraph'
	data-id='es-234'
	>
	Create a new type that uses <code>FormValue</code> and <code>RawFormValue</code> utility types and pass in the return type of the function we created.</p>	</div>
</div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-237"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #d73a49;">function</span><span class="token"> </span><span class="token" style="color: #6f42c1;">createExampleFormGroup</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #d73a49;">return</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormGroup</span><span class="token">(</span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlOne</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleOne</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlTwo</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleTwo</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">,</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token">nonNullable</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">true</span><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">type</span><span class="token"> </span><span class="token" style="color: #6f42c1;">ExampleFormValue</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormValue</span><span class="token">&lt;</span><span class="token" style="color: #6f42c1;">ReturnType</span><span class="token">&lt;</span><span class="token" style="color: #d73a49;">typeof</span><span class="token"> </span><span class="token" style="color: #24292e;">createExampleForm</span><span class="token">&gt;</span><span class="token">&gt;</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">type</span><span class="token"> </span><span class="token" style="color: #6f42c1;">ExampleRawFormValue</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">RawFormValue</span><span class="token">&lt;</span><span class="token" style="color: #6f42c1;">ReturnType</span><span class="token">&lt;</span><span class="token" style="color: #d73a49;">typeof</span><span class="token"> </span><span class="token" style="color: #24292e;">createExampleForm</span><span class="token">&gt;</span><span class="token">&gt;</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Results in the following types:</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> type ExampleFormValue = {</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;">  exampleControlOne?: string | null | undefined;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;">  exampleControlTwo?: string | undefined;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> }</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> type ExampleRawFormValue = {</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> exampleControlOne: string | null;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> exampleControlTwo: string;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> }</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-240"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-238">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-239'
	>
	The types we just created can now be used for typing function arguments, nested form groups, etc.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-243"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-241">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-242'
	>
	<br />
Notice how in the case of a form we also get <code>undefined</code> as a possible type. This is because every control can be <code>disabled</code>, which brings us to the explanation. Disabled form controls won’t be included in the resulting object when you call <code>.value</code> on a control. Should you wish to always get the value of a control, use <code>.getRawValue()</code> instead. The choice what route to take here will depend on your specific use case.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-245"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">readonly</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleFormGroup</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormGroup</span><span class="token">(</span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlOne</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token">{</span><span class="token"> </span><span class="token">value</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleOne</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">,</span><span class="token"> </span><span class="token">disabled</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">true</span><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlTwo</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleTwo</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">,</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token">nonNullable</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">true</span><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> console.log(this.exampleFormGroup.value);</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> {exampleControlTwo: &#039;exampleTwo&#039;}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> console.log(this.exampleFormGroup.getRawValue());</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> {exampleControlOne: &#039;exampleOne&#039;, exampleControlTwo: &#039;exampleTwo&#039;}</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-248"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-246">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-247'
	>
	Should you refactor and how to do it?</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-251"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-249">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-250'
	>
	Refactoring your Angular forms is optional and will depend on many factors, such as the size of your projects, the complexity and number of forms used, and your team or company&#8217;s strategic direction. Refactoring a project that has only one form is not very hard, but multiple ones can present a problem. However, in most scenarios, the refactoring is worth the effort. Don’t be surprised if you end up discovering bugs that you never knew existed before.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-254"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-252">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-253'
	>
	As we often recommend, it’s best to refactor parts of code when you are already modifying it in the course of new development or bug-fixing. The next time you update a form, consider upgrading at least a part of it to utilize typed forms.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-257"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-255">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-256'
	>
	Backward compatibility with untyped controls and migrations</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-260"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-258">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-259'
	>
	Angular Typed forms are fully backward compatible, which means you can update your Angular version without fear you’ll need to refactor your existing application extensively. Upon updating to Angular 14, all your forms will be automatically migrated to their respective untyped versions. <code>FormControl</code> becomes <code>UntypedFormControl</code> and so on.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-263"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-261">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-262'
	>
	Limitations, quirky behaviors, and best practices</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-266"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-264">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-265'
	>
	No support for template-driven forms</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-269"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-267">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-268'
	>
	One of the limitations of Angular Typed Forms is that the Typed Forms API doesn’t work with template-driven forms. If you are working on an older project with many template-driven forms you won’t be able to enjoy these new benefits.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-272"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-270">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-271'
	>
	Binding form controls directly</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-275"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-273">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-274'
	>
	Our recommendation is to always aim to bind form controls directly in the template using <code>formControl</code> instead of <code>formControlName</code>. This will enable you to catch errors as early as possible or not even make them in the first place. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-278"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-276">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-277'
	>
	Using this approach, you’ll be thrown an error if you try to access a control that does not exist, and you will also benefit from the auto-complete function, which further reduces the chance of making an error. Additionally, you protect yourself for the case of future changes because renaming or deleting a <code>FormControl</code> will result in an error in the template.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-280"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Component</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">readonly</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleFormGroup</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormGroup</span><span class="token">(</span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlOne</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleOne</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlTwo</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleTwo</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">,</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token">nonNullable</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">true</span><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Template</span><span class="token">
</span></span><span class="line"><span class="token">&lt;</span><span class="token" style="color: #22863a;">form</span><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">[formGroup]=&quot;exampleFormGroup&quot;&gt;</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">&lt;input</span><span class="token" style="color: #6f42c1;"> formControlNam</span><span class="token">e</span><span class="token" style="color: #d73a49;">=</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">exampleControlThree</span><span class="token" style="color: #032f62;">&quot;</span><span class="token"> </span><span class="token">/&gt;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">&lt;</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #24292e;">form</span><span class="token" style="color: #d73a49;">&gt;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Won&#039;t throw an error</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token">&lt;</span><span class="token" style="color: #22863a;">form</span><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">[formGroup]=&quot;exampleFormGroup&quot;&gt;</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">&lt;input</span><span class="token"> </span><span class="token" style="color: #b31d28;font-style: italic;">[formControl]=&quot;exampleFormGroup.controls.exampleControlThree&quot;</span><span class="token">
</span></span><span class="line"><span class="token">/&gt;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">&lt;</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #24292e;">form</span><span class="token" style="color: #d73a49;">&gt;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Will throw an error in compile time</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-283"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-281">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-282'
	>
	The same recommendation applies for accessing form controls in components. Avoid using <code>get</code> to catch errors earlier in the development process.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-285"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #24292e;">private</span><span class="token"> </span><span class="token" style="color: #24292e;">readonly</span><span class="token"> </span><span class="token" style="color: #24292e;">exampleFormGroup</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormGroup</span><span class="token">(</span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlOne</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleOne</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token">exampleControlTwo</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">new</span><span class="token"> </span><span class="token" style="color: #6f42c1;">FormControl</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleTwo</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">,</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token">nonNullable</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">true</span><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6f42c1;">constructor</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Won&#039;t throw an error </span><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">this</span><span class="token">.</span><span class="token" style="color: #24292e;">exampleFormGroup</span><span class="token">.</span><span class="token" style="color: #6f42c1;">get</span><span class="token">(</span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">exampleControlThree</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Will throw an error </span><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">this</span><span class="token">.</span><span class="token" style="color: #24292e;">exampleFormGroup</span><span class="token">.</span><span class="token" style="color: #24292e;">controls</span><span class="token">.</span><span class="token" style="color: #24292e;">exampleControlThree</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-288"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-286">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-287'
	>
	Why Angular Typed Forms are a win-win</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-291"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-289">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-290'
	>
	Type-safe forms in Angular represent one of the most significant changes in recent Angular history. They don’t require an immediate refactor of your entire codebase, and the migration process is straightforward. In addition, they enhance the developer experience by eliminating the possibility of accessing non-existent attributes or assigning unsupported values to form controls.&nbsp;</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-294"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-292">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-293'
	>
	In fact, there’s hardly a downside to typed forms. They also prevent many bugs while improving maintainability throughout the project&#8217;s lifecycle. Based on experience and the knowledge we’ve attained so far, we’d definitely recommend using Angular Typed Forms on all new projects by default, as well as adopting them in existing ones when creating new forms. As always, we look forward to new additions and improvements to the framework and can only say – always bet on Angular.</p></div>	</div>
</div>
</div>		</div>
	</div><p>The post <a href="https://infinum.com/blog/angular-typed-forms/">Type Smarter, Not Harder – Get the Most of Angular Typed Forms</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</content:encoded>
			</item>
					<item>
				<image>
					<url>38889https://infinum.com/uploads/2023/05/Signal_Artwork-version2-1.webp</url>
				</image>
				<title>Write More Reactive Code with Angular Signals</title>
				<link>https://infinum.com/blog/introducing-angular-signals/</link>
				<pubDate>Wed, 31 May 2023 12:27:44 +0000</pubDate>
				<dc:creator>Đani Pavić</dc:creator>
				<guid isPermaLink="false">https://infinum.com/?p=38889</guid>
				<description>
					<![CDATA[<p>Discover what Angular Signals are, how they work, how they interoperate with RxJS, and the revolutionary changes they bring. </p>
<p>The post <a href="https://infinum.com/blog/introducing-angular-signals/">Write More Reactive Code with Angular Signals</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</description>
				<content:encoded>
					<![CDATA[<div
	class="wrapper"
	data-id="es-534"
	 data-animation-target='inner-items'>
		
			<div class="wrapper__inner">
			<div class="block-blog-content js-block-blog-content">
	
<div class="block-blog-content-sidebar" data-id="es-297">
	</div>

<div class="block-blog-content-main">
	
<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-300"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-298">
	<p	class='typography typography--size-36-text js-typography block-paragraph__paragraph'
	data-id='es-299'
	>
	Angular Signals – a feature introduced in Angular 16 brings a new way of handling reactivity in applications. We discover what they are, how they work, how they interoperate with RxJS, and what revolutionary changes they bring. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-303"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-301">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-302'
	>
	The release of Angular v16 brought a very important feature many developers are already calling the framework’s renaissance – Angular Signals.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-306"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-304">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-305'
	>
	Personally, I wouldn’t say Angular ever fell out of favor, and NPM downloads don&#8217;t necessarily reflect if a framework is good or bad. However, one thing we can agree on is that it has a steeper learning curve compared to, say, React. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-309"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-307">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-308'
	>
	With Signals, this is bound to change because you no longer need complex patterns to start writing performant Angular code. Angular Signals make the platform more approachable to beginners, and in that sense, it does mark the beginning of a completely new phase.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-312"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-310">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-311'
	>
	Angular Signals bring reactivity in a fundamental change </h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-315"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-313">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-314'
	>
	The Angular team’s motivation for introducing this feature was adding fine-grained reactivity into the framework. This concept is fundamentally different from how Angular functions today, where zone.js is used to trigger global change detection for the whole application. The changes introduced will allow:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-318"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="lists" data-id="es-316">
	<ul	class='typography typography--size-16-text-roman js-typography lists__typography'
	data-id='es-317'
	>
	<li>removal of zone.js at a certain point in the future (not imminent future; for now it is here to stay)</li><li>creating a clear model of how data flows through the application</li><li>built-in support for derived state</li><li>synchronizing the parts of the UI that need to be updated</li><li>better interoperability with other reactive libraries like RxJS. The Angular team announced a partnership with major state management libraries like NgRx, RxAngular, and many others in order to support interoperability</li><li>simplification of the entire framework</li></ul></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-321"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-319">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-320'
	>
	Why Angular Signals?</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-324"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-322">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-323'
	>
	First of all, signals’ values are synchronous and always available. How many times did you want to get a simple value from an RxJS chain but had to go through all the hassle of subscribing and unsubscribing to read it? Here are some more upsides to using signals. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-328"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="bullet bullet--left bullet__type--dot bullet__color--infinum block-bullet__bullet" data-id="es-325">
			<div class="bullet__dot"></div>
		<div class="bullet__content">
		<p	class='typography typography--size-20-text js-typography bullet__heading'
	data-id='es-326'
	>
	Local change detection.</p><p	class='typography typography--size-20-text-roman js-typography bullet__paragraph'
	data-id='es-327'
	>
	Whereas zone.js triggered a global change detection check, a signal-based component will be scheduled for change detection check only when a signal read in the template notifies it that it has been changed. This allows for very precise updates.</p>	</div>
</div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-331"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="bullet bullet--left bullet__type--dot bullet__color--infinum block-bullet__bullet" data-id="es-329">
			<div class="bullet__dot"></div>
		<div class="bullet__content">
		<p	class='typography typography--size-20-text js-typography bullet__heading'
	data-id='es-330'
	>
	Reading a value doesn&#8217;t trigger side effects.</p>	</div>
</div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-334"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="bullet bullet--left bullet__type--dot bullet__color--infinum block-bullet__bullet" data-id="es-332">
			<div class="bullet__dot"></div>
		<div class="bullet__content">
		<p	class='typography typography--size-20-text js-typography bullet__heading'
	data-id='es-333'
	>
	Automatic dependencies tracking.</p>	</div>
</div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-337"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-335">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-336'
	>
	Angular Signals and consumers</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-340"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-338">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-339'
	>
	Signals are a system that allows Angular to granularly track where a state is used and updated in the application, which then allows the framework to optimize the application’s rendering. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-342"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-highlighted-text">
	<p	class='typography typography--size-36-text js-typography block-highlighted-text__typography'
	data-id='es-341'
	>
	Angular Signals wrap a value that notifies all the consumers of a particular signal when this value is changed.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-345"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-343">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-344'
	>
	In signals, consumers are any part of the code that uses a signal’s value and wants to be notified about a change in that value. When a change occurs, the signal notifies all the consumers, which then act upon the change in the signal’s value.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-348"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-346">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-347'
	>
	A signal can contain any value. It can be either read-only or writable, and it can be called anywhere in the code. Let&#8217;s say you define a signal in a service. You can then use it in a template, component, pipe, or even other services. A signal value is reactive.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-351"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-349">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-350'
	>
	Where to find Angular Signals </h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-354"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-352">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-353'
	>
	Signals are available as of Angular version 16 as a developer preview, which allows you to experiment with them. Even though the majority of the API is stable and functional, this is a major change, so you can expect bugs, and the API is still subject to change.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-357"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-355">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-356'
	>
	We would recommend avoiding using Signals in production projects until they are 100% stable, and expect this to happen in Angular version 17. The developer preview only lists a basic subset of the API, while the inputs, outputs, etc., are announced for v17+.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-360"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-358">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-359'
	>
	Overview of Angular Signals syntax and usage</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-363"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-361">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-362'
	>
	Creating a signal </h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-366"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-364">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-365'
	>
	You can create a new signal by calling a <code>signal()</code> function and passing in an argument that contains its initial value. Think of it as <code>BehaviorSubject</code> in the RxJS, but without the subscribe part.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-368"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal </span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">signal</span><span class="token">(</span><span class="token" style="color: #005cc5;">false</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Reads a signal</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6f42c1;">isActive</span><span class="token">(</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-371"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-369">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-370'
	>
	Marking signal as read-only </h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-374"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-372">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-373'
	>
	The method <code>asReadonly()</code> will return a signal that is non-writeable. You can access its value, but it does not allow changing the signal.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-376"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">signal</span><span class="token">(</span><span class="token" style="color: #005cc5;">false</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Returns read only version of isActive signal</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">readonlyIsActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #24292e;">isActive</span><span class="token">.</span><span class="token" style="color: #6f42c1;">asReadonly</span><span class="token">(</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-379"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-377">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-378'
	>
	Set a new signal value </h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-382"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-380">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-381'
	>
	To set or change the value of a signal programmatically, call the <code>set()</code> method.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-384"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Sets value of isActive signal to true</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #24292e;">isActive</span><span class="token">.</span><span class="token" style="color: #6f42c1;">set</span><span class="token">(</span><span class="token" style="color: #005cc5;">true</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-387"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-385">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-386'
	>
	Update signal value based on the previous state</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-390"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-388">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-389'
	>
	If a new state is derived from an old one, use the <code>update()</code> method where the first argument of the callback function is the previous state of the signal. You can then use it to calculate the new state.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-392"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Updates the state based on the previous value</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #24292e;">isActive</span><span class="token">.</span><span class="token" style="color: #6f42c1;">update</span><span class="token">(</span><span class="token" style="color: #e36209;">value</span><span class="token"> </span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> </span><span class="token" style="color: #d73a49;">!</span><span class="token" style="color: #24292e;">value</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-395"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-393">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-394'
	>
	Mutating a signal</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-398"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-396">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-397'
	>
	When working with arrays or objects, use the <code>mutate()</code> method to trigger updates. This is very useful because mutating a signal that contains an object will trigger change detection, whereas using a conventional approach wouldn’t because the object reference would remain the same. Before signals, you would either have to create a new array or object or call change detection manually.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-400"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">items</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">signal</span><span class="token">(</span><span class="token">{</span><span class="token">content</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">Item content</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">}</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Updates the property of an object</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #24292e;">items</span><span class="token">.</span><span class="token" style="color: #6f42c1;">mutate</span><span class="token">(</span><span class="token" style="color: #e36209;">value</span><span class="token"> </span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #24292e;">value</span><span class="token">.</span><span class="token" style="color: #24292e;">content</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">Updated item content</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-403"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-401">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-402'
	>
	Computed signals</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-406"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-404">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-405'
	>
	Computed signals derive their value based on one or more other signals. Whenever one of those signals changes, the computed signal also changes.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-409"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-407">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-408'
	>
	It’s important to note that computed values are cached, meaning that every future read of that computed signal will return cached values instead of recalculating them, until the signals computed depend on the changes. You can think of them as pure pipes where the <code>transform()</code> function won’t run until the value changes. Computed signals take a derivation function to calculate value, and it is not possible to programmatically set the value using <code>set</code> or <code>mutate</code> methods. The dependencies inside the computed signals are dynamic, which means if you have some expensive nested signal computations, only the ones read during computations will be executed.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-412"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-410">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-411'
	>
	There’s another important note here – anything derived from a signal is also a signal.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-414"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">signal</span><span class="token">(</span><span class="token" style="color: #005cc5;">false</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal based on isActive</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActiveLabel</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">computed</span><span class="token">(</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> 
</span></span><span class="line"><span class="token">   </span><span class="token" style="color: #6f42c1;">isActive</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token" style="color: #d73a49;">?</span><span class="token"> </span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">Active</span><span class="token" style="color: #032f62;">&#039;</span><span class="token"> </span><span class="token" style="color: #d73a49;">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">Inactive</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-417"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-415">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-416'
	>
	Running side effects</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-420"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-418">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-419'
	>
	The <code>effect</code> function is used for triggering side effects when one or more signals inside it change. Every effect function will run at least once, and every signal that has been called inside it becomes tracked. If any of those signals change, the effect function will execute again.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-423"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-421">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-422'
	>
	Use the <code>effect</code> function wisely and don&#8217;t use it to propagate state changes, as you can unintentionally introduce circular references or change detection cycles. An effect can only be called inside of the injection context, similar to the inject API. Meaning you cannot register an effect inside of a function call, for example.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-426"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-424">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-425'
	>
	Effects automatically destroy when the context they were created in (component/service) gets destroyed or they can be removed manually using the destroy method. Always make sure to destroy an effect, similar to how you would handle subscriptions in an app, or you risk memory leaks.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-428"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">signal</span><span class="token">(</span><span class="token" style="color: #005cc5;">false</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> 
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Registers new effect which will run whenever isActive changes</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6f42c1;">effect</span><span class="token">(</span><span class="token">(</span><span class="token">)</span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #24292e;">console</span><span class="token">.</span><span class="token" style="color: #6f42c1;">log</span><span class="token">(</span><span class="token" style="color: #032f62;">`</span><span class="token" style="color: #032f62;">The isActive signal changed value to </span><span class="token" style="color: #032f62;">${</span><span class="token" style="color: #6f42c1;">isActive</span><span class="token" style="color: #032f62;">(</span><span class="token" style="color: #032f62;">)</span><span class="token" style="color: #032f62;">}</span><span class="token" style="color: #032f62;">`</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">}</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-431"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-429">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-430'
	>
	Interoperability with RxJS</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-434"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-432">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-433'
	>
	The introduction of signals doesn’t mean that the Angular team is abandoning RxJS. In fact, they will make RxJS integration easier.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-437"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-435">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-436'
	>
	While signals are great for handling synchronous reactivity, they are not a good out-of-the-box solution for asynchronous reactivity (think API calls). The reason for this is that signals are synchronous and will set the value that came in last. For example, since the time of API calls varies, it may happen that a wrong value is set. However, you can transform an observable into a signal by calling <code>toSignal()</code> or vice versa by calling <code>toObservable()</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-440"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-438">
	<h4	class='typography typography--size-30-text js-typography block-heading__heading'
	data-id='es-439'
	>
	toSignal</h4></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-443"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-441">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-442'
	>
	The <code>toSignal</code> function internally subscribes to the given Observable and updates the returned signal any time the Observable emits a value. This subscription is created immediately as opposed to waiting until the signal is read.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-446"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-444">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-445'
	>
	The signature of the <code>toSignal</code> function supports both synchronous and asynchronous Observables. Angular Signals always need to have an initial value. In case one is not provided, the signal value remains undefined until an Observable emits the first value. This is useful if the Observable turned to signal is, for example, an API call.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-449"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-447">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-448'
	>
	The unsubscribe part is the same as the effect when the context in which the signal has been created is destroyed.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-451"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates an source observable</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive$</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">of</span><span class="token">(</span><span class="token" style="color: #005cc5;">true</span><span class="token">)</span><span class="token">.</span><span class="token" style="color: #6f42c1;">pipe</span><span class="token">(</span><span class="token" style="color: #6f42c1;">delay</span><span class="token">(</span><span class="token" style="color: #005cc5;">5000</span><span class="token">)</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> 
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Transforms an observable to a signal with initial value of false</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> The value of signal will be set to true after 5 seconds</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">toSignal</span><span class="token">(</span><span class="token" style="color: #24292e;">isActive$</span><span class="token">,</span><span class="token"> </span><span class="token">{</span><span class="token">initialValue</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">false</span><span class="token">}</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-454"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-452">
	<h4	class='typography typography--size-30-text js-typography block-heading__heading'
	data-id='es-453'
	>
	toObservable</h4></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-457"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-455">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-456'
	>
	<code>toObservable</code> is a function that takes an Angular Signals and returns an Observable. It does this by creating an effect under the hood when the Observable is subscribed to. This effect takes values from the signal and streams them to subscribers. All values are asynchronous. The function <code>toObservable</code> must be called in an injection context.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-459"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">signal</span><span class="token">(</span><span class="token" style="color: #005cc5;">true</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> 
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Transforms a signal to an observable</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive$</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">toObservable</span><span class="token">(</span><span class="token" style="color: #24292e;">isActive</span><span class="token">)</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-462"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-460">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-461'
	>
	Function calls in a template</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-465"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-463">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-464'
	>
	Over the years, Angular developers have learned to avoid calling functions inside templates because a function re-runs every change detection and used pure pipes instead. This would cause expensive computations to run multiple times unnecessarily if the passed arguments did not change.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-468"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-466">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-467'
	>
	In a signal-based component, this idea no longer applies because the expressions will only re-evaluate as a result of a signal dependency change.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-471"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-469">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-470'
	>
	With signals, we no longer have to care about handling subscriptions. It is absolutely fine to call a signal function in the template since only the part that depends on that signal will be updated.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-473"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-javascript github-light" data-language="javascript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> example.component.ts</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActive</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">signal</span><span class="token">(</span><span class="token" style="color: #005cc5;">false</span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> 
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> Creates new signal based on isActive</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">isActiveLabel</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #6f42c1;">computed</span><span class="token">(</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> 
</span></span><span class="line"><span class="token">     </span><span class="token" style="color: #6f42c1;">isActive</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token" style="color: #d73a49;">?</span><span class="token"> </span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">Active</span><span class="token" style="color: #032f62;">&#039;</span><span class="token"> </span><span class="token" style="color: #d73a49;">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&#039;</span><span class="token" style="color: #032f62;">Inactive</span><span class="token" style="color: #032f62;">&#039;</span><span class="token">
</span></span><span class="line"><span class="token"> </span><span class="token">)</span><span class="token">
</span></span><span class="line"><span class="token"> 
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> example.component.html</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> isActiveLabel will only run when the signal changes</span><span class="token">
</span></span><span class="line"><span class="token">&lt;</span><span class="token" style="color: #22863a;">p</span><span class="token">&gt;</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token">{</span><span class="token">{</span><span class="token"> </span><span class="token" style="color: #6f42c1;">isActiveLabel</span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token">}</span><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">&lt;/</span><span class="token" style="color: #22863a;">p</span><span class="token">&gt;</span><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-476"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-474">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-475'
	>
	Proposed Signal APIs not yet available in the developer preview</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-479"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-477">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-478'
	>
	During the signals’ RFC phase, the Angular team proposed a set of new APIs. These are not available in the developer preview of Angular version 16 but should become so in future versions. Since those APIs are still in the works, only basic descriptions are given.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-482"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-480">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-481'
	>
	Declare a component as signal-based</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-485"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-483">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-484'
	>
	To mark a component as signal-based, you have to set the property of the signal in the component decorator to <code>true</code>. Given that most newly generated components in newer projects will be signal-based and standalone, the Angular team is working on a solution to mark components as both standalone and signal-based by default when generating new components to reduce the boilerplate.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-488"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-486">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-487'
	>
	Lifecycle methods in signal-based components</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-491"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-489">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-490'
	>
	Traditional zone-based components have eight different lifecycle methods, but since they are tightly coupled with the current Angular change detection model, they are redundant when using signals.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-494"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-492">
	<p	class='typography typography--size-20-text-roman js-typography block-paragraph__paragraph'
	data-id='es-493'
	>
	In signal-based components, only <code>ngOnInit</code> and <code>ngOnDestroy</code> exist from the original lifecycle methods, while three new ones are proposed to be added to supplement signal-based components. These should include <code>afterNextRender</code>, <code>afterRender</code>, and <code>afterRenderEffect</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-497"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-495">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-496'
	>
	Inputs and outputs in signal-based components</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-500"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-498">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-499'
	>
	In signal-based components, all component inputs are proposed to be signals. This means you should be able to use them as regular read-only signals out of the box. Unlike traditional inputs, signal inputs are not decorators!</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-503"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-501">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-502'
	>
	Angular Signals do not affect traditional outputs, but in order to be consistent with inputs API, a new output function will be introduced with a syntax similar to the inputs.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-506"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-504">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-505'
	>
	Signal-based components additionally have access to a new type of input, model inputs. This creates an input-output binding between parent and child components. The syntax proposed is banana in a box, similar to the <code>ngModel</code>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-509"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-507">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-508'
	>
	Always bet on Angular</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-512"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-510">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-511'
	>
	The introduction of Angular Signals is not just another Angular rewrite like the move from AngularJS to Angular 2. It is an additive change, a gradual change, and it’s completely backward-compatible.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-515"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-513">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-514'
	>
	Signals don&#8217;t mean that you can throw everything you know out the window immediately. They work on a full opt-in basis. You can refactor, use them only in the new features you develop, mix and match with RxJS or simply continue to use RxJS. All of your RxJS knowledge is still relevant. No approach is wrong here, and it is completely up to you or your team to decide which one to take.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-518"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-516">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-517'
	>
	That being said, the logical next step would probably be to try signals out and use them on newer features or features built from scratch and just take it from there.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-521"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-519">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-520'
	>
	Overall, signals are a huge change and a major leap forward for Angular. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-523"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-highlighted-text">
	<p	class='typography typography--size-36-text js-typography block-highlighted-text__typography'
	data-id='es-522'
	>
	Alongside new standalone APIs, <strong>signals</strong> make entering into the Angular ecosystem simpler with the added benefit of better performance. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-526"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-524">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-525'
	>
	Signals will substitute many RxJS patterns, which, although very logical once you get the hang of them, have a steep learning curve for beginners, which tends to put people off.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-529"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-527">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-528'
	>
	We believe Angular is a great choice for projects as it is very stable, performant, comes with almost all of the features you will need out-of-the-box and is now easier to get started with than ever before. As signals are currently in development preview, consider this blog post a mere Part 1. </p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-532"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-530">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-531'
	>
	Time, experience, and practical usage will reveal the best practices and patterns for signals. Always bet on Angular.</p></div>	</div>
</div>
</div>		</div>
	</div><p>The post <a href="https://infinum.com/blog/introducing-angular-signals/">Write More Reactive Code with Angular Signals</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</content:encoded>
			</item>
		
	</channel>
</rss>