<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nalaka Jayasena</title>
    <description>The latest articles on DEV Community by Nalaka Jayasena (@nalaka).</description>
    <link>https://dev.to/nalaka</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F27542%2F6a16973a-4275-48ff-bd7a-cbda492f8063.jpg</url>
      <title>DEV Community: Nalaka Jayasena</title>
      <link>https://dev.to/nalaka</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nalaka"/>
    <language>en</language>
    <item>
      <title>A tour of Angular for web developers: Composing the user interface with components</title>
      <dc:creator>Nalaka Jayasena</dc:creator>
      <pubDate>Sun, 23 Aug 2020 18:45:21 +0000</pubDate>
      <link>https://dev.to/nalaka/a-tour-of-angular-for-web-developers-composing-the-user-interface-with-components-1amj</link>
      <guid>https://dev.to/nalaka/a-tour-of-angular-for-web-developers-composing-the-user-interface-with-components-1amj</guid>
      <description>&lt;p&gt;This is the second part of our brief tour of the Angular framework. In this post, we take a closer look at the primary building block of an angular application, the &lt;strong&gt;&lt;em&gt;component&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This series is best read in sequence, as each one usually builds upon the previous ones. The target audience is somewhat experienced web developers, specially those coming from another framework like React, Vue, or Ember. However, even if you are a beginner with a decent grasp of HTML, CSS, TypeScript, HTTP and NodeJS, you should still be able to easily follow along.  and at the end of the series, have a good idea of how Angular works and how to go about using it to build modern web applications.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The journey so far&lt;/li&gt;
&lt;li&gt;The anatomy of a component&lt;/li&gt;
&lt;li&gt;Interpolation&lt;/li&gt;
&lt;li&gt;Pipes&lt;/li&gt;
&lt;li&gt;A new pipe&lt;/li&gt;
&lt;li&gt;A new component&lt;/li&gt;
&lt;li&gt;Repeating UI elements&lt;/li&gt;
&lt;li&gt;Conditionally rendering elements&lt;/li&gt;
&lt;li&gt;Binding to properties, events, and attributes&lt;/li&gt;
&lt;li&gt;Passing data between components&lt;/li&gt;
&lt;li&gt;What's next&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The journey so far
&lt;/h2&gt;

&lt;p&gt;In the previous post, we created a new Angular workspace and then added a web application project to it. If you haven't read through that yet, please go ahead and do.&lt;/p&gt;


&lt;div class="ltag__link"&gt;
  &lt;a href="/nalaka" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__pic"&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NLXUaB9C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://res.cloudinary.com/practicaldev/image/fetch/s--pyeVy0CL--/c_fill%2Cf_auto%2Cfl_progressive%2Ch_150%2Cq_auto%2Cw_150/https://dev-to-uploads.s3.amazonaws.com/uploads/user/profile_image/27542/6a16973a-4275-48ff-bd7a-cbda492f8063.jpg" alt="nalaka"&gt;
    &lt;/div&gt;
  &lt;/a&gt;
  &lt;a href="/nalaka/a-tour-of-angular-for-web-developers-4he1" class="ltag__link__link"&gt;
    &lt;div class="ltag__link__content"&gt;
      &lt;h2&gt;A tour of Angular for web developers&lt;/h2&gt;
      &lt;h3&gt;Nalaka Jayasena ・ Aug 22 '20&lt;/h3&gt;
      &lt;div class="ltag__link__taglist"&gt;
        &lt;span class="ltag__link__tag"&gt;#angular&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#webdev&lt;/span&gt;
        &lt;span class="ltag__link__tag"&gt;#tutorial&lt;/span&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/a&gt;
&lt;/div&gt;


&lt;p&gt;Here's a recap of the commands we used:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Install ng (The Angular CLI)&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @angular/cli

&lt;span class="c"&gt;# Create an empty workspace&lt;/span&gt;
ng new into-angular &lt;span class="se"&gt;\&lt;/span&gt;
        &lt;span class="nt"&gt;--strict&lt;/span&gt; &lt;span class="nt"&gt;--create-application&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"false"&lt;/span&gt;

&lt;span class="c"&gt;# Create a web app project&lt;/span&gt;
ng generate application hello &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--strict&lt;/span&gt;  &lt;span class="nt"&gt;--inline-template&lt;/span&gt;  &lt;span class="nt"&gt;--inline-style&lt;/span&gt;

&lt;span class="nb"&gt;cd &lt;/span&gt;into-angular  

&lt;span class="c"&gt;# Run hello project in local dev server&lt;/span&gt;
ng serve hello &lt;span class="nt"&gt;--open&lt;/span&gt;             

&lt;span class="c"&gt;# Run unit tests for hello project&lt;/span&gt;
ng &lt;span class="nb"&gt;test &lt;/span&gt;hello

&lt;span class="c"&gt;# Run end-to-end tests for hello project&lt;/span&gt;
ng e2e hello

&lt;span class="c"&gt;# Do a production build on the hello project&lt;/span&gt;
ng build hello &lt;span class="nt"&gt;--prod&lt;/span&gt;

&lt;span class="c"&gt;# Install serve (simple web server)&lt;/span&gt;
npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; serve

&lt;span class="c"&gt;# Serve the production build locally&lt;/span&gt;
serve into-angular/dist/hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  The anatomy of a component
&lt;/h2&gt;

&lt;p&gt;Now open the  &lt;code&gt;into-angular/projects/hello/src/app/app.component.ts&lt;/code&gt; file. It defines &lt;code&gt;AppComponent&lt;/code&gt;,  the component that sits at the top of the component hierarchy making up our apps' user interface.&lt;/p&gt;

&lt;p&gt;The generator has populated this file with some content useful for Angular novices. After having a look at that, delete everything and replace it with:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div&amp;gt;
      &amp;lt;h1&amp;gt;Hello {{ name }}!&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;h1 { color: darkred; }&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This is the classical "Hello World Program"-  a minimal program that displays the text "Hello World!".&lt;/p&gt;

&lt;p&gt;If the &lt;code&gt;ng serve&lt;/code&gt; command  was already running when the above change was made, you should see the development server picking up the change to the &lt;code&gt;app.component.ts&lt;/code&gt; file, do a build, and hot reload the browser; this time with just the text &lt;em&gt;"Hello World!"&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Let's take a closer look:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iYQiv1_G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ulqdo67pvlotpvst2l7e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iYQiv1_G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/ulqdo67pvlotpvst2l7e.png" alt="The anatomy of a simple Angular component" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;em&gt;@Component&lt;/em&gt; decorator "decorates" the plain class &lt;code&gt;AppComponent&lt;/code&gt; with component metadata and identifies it as a component.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;em&gt;selector&lt;/em&gt; is a CSS selector expression for locating DOM nodes where this component should be attached to.&lt;/li&gt;
&lt;li&gt;The &lt;em&gt;template&lt;/em&gt; is a string of HTML that represents the structure of the contents of this component.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;styles&lt;/code&gt; is an array of CSS strings that applies styling to the DOM elements making up this component.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Having the components' code, the HTML template, and the CSS styles in a single &lt;code&gt;app.component.ts&lt;/code&gt; file was  a nice feature. However, for more complex components, it is more convenient to move the HTML and CSS files to separate files. We can do that with this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;templateUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app.component.html&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;styleUrls&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./app.component.css&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In fact, this is the default behavior. It is what would have been generated if we had omitted the &lt;code&gt;--inline-template&lt;/code&gt;, and &lt;code&gt;--inline-style&lt;/code&gt; options to the &lt;code&gt;ng generate application&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Interpolation
&lt;/h2&gt;

&lt;p&gt;The HTML template in above example contains a &lt;a href="https://angular.io/guide/interpolation"&gt;template expression&lt;/a&gt; enclosed in a pair of double braces.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight handlebars"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello &lt;span class="k"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="k"&gt;}}&lt;/span&gt;!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Template expressions are side-effect free JavaScript expressions that are evaluated in the context of a component object. In this case, the context is:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;world&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Since the components' name property is initialized to the value &lt;code&gt;'world'&lt;/code&gt;, when the component first renders, we see that the &lt;em&gt;text node&lt;/em&gt; inside the &lt;em&gt;h1&lt;/em&gt; element contains the text &lt;code&gt;Hello world!&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;If we programmatically change change the value of the components' &lt;code&gt;name&lt;/code&gt; property, Angular will detect the change, re-evaluate the template expression, and update the DOM.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Pipes
&lt;/h2&gt;

&lt;p&gt;Try changing the template expression to:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight handlebars"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello &lt;span class="k"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;uppercase&lt;/span&gt; &lt;span class="k"&gt;}}&lt;/span&gt;!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;What do you see on the screen. Can you guess what's going on?&lt;/p&gt;

&lt;p&gt;Try changing to:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight handlebars"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello &lt;span class="k"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;uppercase&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;titlecase&lt;/span&gt; &lt;span class="k"&gt;}}&lt;/span&gt;!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;What do you see on the screen?&lt;/p&gt;

&lt;p&gt;The "&lt;code&gt;|&lt;/code&gt;" character is used in template expressions to act as a "pipe"  that pumps the left-side expression as a parameter to the function on the right. These can be chained as we see above to form a "pipe line" through which the value of the left most expression flows through. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The expression &lt;code&gt;name&lt;/code&gt; starts with the value &lt;em&gt;"world"&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;The expression &lt;code&gt;name | uppercase&lt;/code&gt; is equivalent to &lt;code&gt;uppercase("world")&lt;/code&gt;, which evaluates to &lt;em&gt;WORLD&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;And &lt;code&gt;name | uppercase | titlecase&lt;/code&gt; is equivalent to &lt;code&gt;titlecase(uppercase(name)&lt;/code&gt; which evaluates to &lt;code&gt;titlecase("WORLD")&lt;/code&gt; which finally evaluates to &lt;em&gt;"World"&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So we can use pipes to transform our template expressions. Angular comes with a bunch of &lt;a href="https://angular.io/api?type=pipe"&gt;built-in pipes&lt;/a&gt;, let's try the &lt;em&gt;date&lt;/em&gt; pipe to format a time string:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight handlebars"&gt;&lt;code&gt;&lt;span class="k"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;currentTime&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;date&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'h:mm a on MMMM d, y'&lt;/span&gt; &lt;span class="k"&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Of course you need the &lt;code&gt;currentTime&lt;/code&gt; property set in the component:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;currentTime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;It is also quite easy to &lt;a href="https://angular.io/guide/pipes#creating-pipes-for-custom-data-transformations"&gt;create our own custom pipe&lt;/a&gt;- it is just a simple function after all.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  A new pipe
&lt;/h2&gt;

&lt;p&gt;Let's create a &lt;code&gt;funkycase&lt;/code&gt; pipe that changes &lt;em&gt;"world"&lt;/em&gt; to &lt;em&gt;"wOrLd"&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng generate pipe funkycase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Notice that we didn't specify a project name as the &lt;code&gt;hello&lt;/code&gt; project is used by default.&lt;/p&gt;

&lt;p&gt;Run the unit tests with &lt;code&gt;ng test&lt;/code&gt; - notice the new test that was created for our "funkycase pipe"&lt;/p&gt;

&lt;p&gt;Try applying our new pipe:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight handlebars"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;h1&amp;gt;&lt;/span&gt;Hello &lt;span class="k"&gt;{{&lt;/span&gt; &lt;span class="nv"&gt;name&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; &lt;span class="nv"&gt;funkycase&lt;/span&gt; &lt;span class="k"&gt;}}&lt;/span&gt;!&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We only get &lt;em&gt;Hello !&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The template expression has produced and empty result- i.e. &lt;code&gt;funkycase("world")&lt;/code&gt; hasn't returned a valid value. Let's open the generated &lt;code&gt;into-angular/projects/hello/src/app/funkycase.pipe.ts&lt;/code&gt; and fix this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Pipe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;PipeTransform&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Pipe&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;funkycase&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;FunkycasePipe&lt;/span&gt; &lt;span class="k"&gt;implements&lt;/span&gt; &lt;span class="nx"&gt;PipeTransform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...&lt;/span&gt;&lt;span class="nx"&gt;args&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;[]):&lt;/span&gt; &lt;span class="nx"&gt;unknown&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[...&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
          &lt;span class="nx"&gt;index&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
            &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;character&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toUpperCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;[Line 3-5]&lt;/strong&gt; The &lt;code&gt;@Pipe&lt;/code&gt; decorator marks our &lt;code&gt;FunkycasePipe&lt;/code&gt; class as a pipe&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[Line 6-7]&lt;/strong&gt; Our class implements &lt;code&gt;transform()&lt;/code&gt; from the  &lt;code&gt;PipeTransform&lt;/code&gt; interface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[Line 9]&lt;/strong&gt; First we use the &lt;code&gt;...&lt;/code&gt; syntax to spread out the string valued input into an array of strings&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[Line 10-13]&lt;/strong&gt; Then we map over this array collecting the "lowercase version if the index is even" and the "uppercase version otherwise" to a new array&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[Line 15]&lt;/strong&gt; Finally we join this new array to form the end result&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;[Line 18]&lt;/strong&gt; If the input value is not a string just return it back&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's add some more unit tests for this in &lt;code&gt;app.component.spec.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;handles a string&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;FunkycasePipe&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;apple&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;aPpLe&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;handles a number by passing it through unchanged&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;pipe&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;FunkycasePipe&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pipe&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;)).&lt;/span&gt;&lt;span class="nx"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run &lt;code&gt;ng test&lt;/code&gt; to see if all is still well.&lt;/p&gt;

&lt;p&gt;You may get an error regarding &lt;code&gt;funkycase&lt;/code&gt; not found from the AppComponnt unit tests. This is because the "Test Bed" used for running the AppComponent unit tests doesn't declare the &lt;code&gt;FunkyTestPipe&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;We can fix this in the &lt;code&gt;app.component.spec.ts&lt;/code&gt; file, in the &lt;code&gt;beforeEach&lt;/code&gt; call,  change:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gi"&gt;+- declarations: [AppComponent, FunkycasePipe],
&lt;/span&gt;&lt;span class="gd"&gt;-- declarations: [AppComponent],
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Why did you not get this error when running the app? This is because the &lt;code&gt;ng generate pipe&lt;/code&gt; command updated the &lt;code&gt;app.module.ts&lt;/code&gt; and added the &lt;code&gt;FunkyTestPipe&lt;/code&gt; to the declarations array in the module metadata object.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  A new component
&lt;/h2&gt;

&lt;p&gt;Let's create a new component:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng g component foobar &lt;span class="nt"&gt;-st&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This time, we've used the shorthand syntax:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;g&lt;/code&gt; is short for &lt;code&gt;generate&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-s&lt;/code&gt; is short for &lt;code&gt;--inline-styles&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-t&lt;/code&gt; is short for &lt;code&gt;--inline-templates&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Two files are generated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;into-angular/projects/hello/src/app/foobar/foobar.component.ts&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;into-angular/projects/hello/src/app/foobar/foobar.component.spec.ts&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the &lt;code&gt;AppModule&lt;/code&gt; definition in  &lt;code&gt;app.module.ts&lt;/code&gt; file is updated to add the &lt;code&gt;FoobarComponent&lt;/code&gt; to its list of &lt;a href="https://angular.io/guide/bootstrapping#the-declarations-array"&gt;declarations&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;NgModule&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;declarations&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;FunkycasePipe&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;FoobarComponent&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;imports&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;BrowserModule&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;providers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
  &lt;span class="na"&gt;bootstrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;AppComponent&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;AppModule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;What this means is, that the &lt;code&gt;FoobarComponent&lt;/code&gt; belongs to the &lt;code&gt;AppModule&lt;/code&gt; .&lt;/p&gt;

&lt;p&gt;As we can see, we also have &lt;code&gt;FunkycasePipe&lt;/code&gt; in the declarations metadata field. Also, an Angular &lt;a href="https://angular.io/api/core/Component"&gt;component&lt;/a&gt; is really a special case of what is known as a "&lt;a href="https://angular.io/api/core/Directive"&gt;directive&lt;/a&gt;". Components, pipes, and directives are known as &lt;a href="https://angular.io/guide/glossary#declarable"&gt;declarables&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Every component, pipe, and directive should belong to &lt;strong&gt;&lt;em&gt;one and only one&lt;/em&gt;&lt;/strong&gt; Angular module. This is because Angular uses &lt;a href="https://angular.io/guide/ngmodules"&gt;NgModules&lt;/a&gt; to group those three types of things and allow those to refer to each other.&lt;/p&gt;

&lt;p&gt;So, since both the &lt;code&gt;AppComponent&lt;/code&gt; and &lt;code&gt;FunkycasePipe&lt;/code&gt; belong to the &lt;code&gt;AppModule&lt;/code&gt;, we can reference the &lt;code&gt;FunkycasePipe&lt;/code&gt;  as  &lt;code&gt;funkycase&lt;/code&gt; pipe from inside the HTML template of the &lt;code&gt;AppComponent&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Open the &lt;code&gt;app.component.ts&lt;/code&gt; file. There is no import statement for &lt;code&gt;FunkycasePipe&lt;/code&gt; in that file, but the HTML template has the expression &lt;code&gt;{{ name | funkycase }}&lt;/code&gt;.  And it works!&lt;/p&gt;

&lt;p&gt;Remove &lt;code&gt;FunkycasePipe&lt;/code&gt; from the AppModule's &lt;code&gt;declrations&lt;/code&gt; field and see what happens.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ERROR in projects/hello/src/app/app.component.ts:8:20 - error NG8004: No pipe found with name 'funkycase'.

8       &amp;lt;p&amp;gt;{{ name | funkycase }}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Revert that change to fix.&lt;/p&gt;

&lt;p&gt;Let's use our new component inside the AppComponent. Because the &lt;code&gt;selector&lt;/code&gt; metadata field for &lt;code&gt;FoobarComponent&lt;/code&gt; is set to &lt;em&gt;app-foobar&lt;/em&gt;, we only need to append the following to the &lt;code&gt;AppComponent&lt;/code&gt; template:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;app-foobar&amp;gt;&amp;lt;/app-foobar&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Run &lt;code&gt;ng test&lt;/code&gt; and &lt;code&gt;ng e2e&lt;/code&gt;, just in case we broke anything. Everything should check out.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Repeating UI elements
&lt;/h2&gt;

&lt;p&gt;Right now, our &lt;code&gt;FoobarComponent&lt;/code&gt; just display the text "foobar works!". Let's go work on it.&lt;/p&gt;

&lt;p&gt;Change the template to:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let item of items"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ item }}&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And add the &lt;code&gt;items&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;foo&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;bar&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;a href="https://angular.io/api/common/NgForOf"&gt;ngFor&lt;/a&gt; is a structural directive. It is called an structural directive because it affect the structure of the view by creating or removing elements. &lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Conditionally rendering elements
&lt;/h2&gt;

&lt;p&gt;Another structural directive is &lt;a href="https://angular.io/api/common/NgIf"&gt;ngIf&lt;/a&gt;, let's see it in action by replacing he &lt;code&gt;FoobarComponent&lt;/code&gt; template with:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;Your options&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;*ngFor=&lt;/span&gt;&lt;span class="s"&gt;"let item of items"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ item }}&lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"selectedItem == ''"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Please type-in one of the options.
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"items.includes(selectedItem)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    Selected option is: &lt;span class="nt"&gt;&amp;lt;strong&amp;gt;&lt;/span&gt;{{ selectedItem }}&lt;span class="nt"&gt;&amp;lt;/strong&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And adding the &lt;code&gt;selectedItem&lt;/code&gt; property:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;selectedItem&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;At this point, our app should look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SLZ1kF6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bjilfqnv1c0b10vlz0bd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SLZ1kF6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/bjilfqnv1c0b10vlz0bd.png" alt="App screenshot with Foobar component in view" width="241" height="246"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Binding our component to the DOM element
&lt;/h2&gt;

&lt;p&gt;Let's add an input element where we can type-in our selection. Add this HTML to the end of the FoobarComponent template (between line 12 and 13 of previous code listing):&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt;
    &lt;span class="na"&gt;#txt&lt;/span&gt;
    &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"text"&lt;/span&gt;
    &lt;span class="na"&gt;[value]=&lt;/span&gt;&lt;span class="s"&gt;"selectedItem"&lt;/span&gt;
    &lt;span class="na"&gt;[attr.aria-label]=&lt;/span&gt;&lt;span class="s"&gt;"ariaLabel"&lt;/span&gt;
    &lt;span class="na"&gt;[class]=&lt;/span&gt;&lt;span class="s"&gt;"customClasses"&lt;/span&gt;
    &lt;span class="na"&gt;[style]=&lt;/span&gt;&lt;span class="s"&gt;"customStyles"&lt;/span&gt;
  &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;(click)=&lt;/span&gt;&lt;span class="s"&gt;"handleClick(txt.value)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Select&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;p&lt;/span&gt; &lt;span class="na"&gt;*ngIf=&lt;/span&gt;&lt;span class="s"&gt;"msg != ''"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;{{ msg }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Also add these properties in our component:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;ariaLabel&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Option to select&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;customClasses&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;class1 class2&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;customStyles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;width: 200px; background-color: lightblue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;We have a bunch of new concepts in this one short code snippet:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The&lt;code&gt;#txt&lt;/code&gt; syntax declares a &lt;a href="https://angular.io/guide/template-reference-variables"&gt;template reference variable&lt;/a&gt; with the name &lt;code&gt;txt&lt;/code&gt;, which we can use to refer to the corresponding DOM element, as done at line 10 above.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;[value]="selectedItem"&lt;/code&gt; is a &lt;a href="https://angular.io/guide/property-binding"&gt;property binding&lt;/a&gt;. This binds the &lt;code&gt;selectedItem&lt;/code&gt; property on our component with the &lt;code&gt;value&lt;/code&gt; property on the DOM element. The binding is one-way. When the &lt;code&gt;selectedItem&lt;/code&gt; property changes, the DOM property is updated. But when the &lt;code&gt;value&lt;/code&gt; DOM property is updated as a result of user interaction on the web page, that change does NOT automatically updates the &lt;code&gt;selectedItem&lt;/code&gt; property on the component.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;[attr.aria-label]="ariaLabel"&lt;/code&gt; is an &lt;a href="https://angular.io/guide/attribute-binding#attribute-binding"&gt;attribute binding&lt;/a&gt;. The reason for having this type of binding is that there are some &lt;strong&gt;HTML element attributes&lt;/strong&gt; that do not have corresponding &lt;strong&gt;DOM properties&lt;/strong&gt;. Like. for example, the &lt;code&gt;aria-label&lt;/code&gt; attribute.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;[class]="customClasses"&lt;/code&gt; is a &lt;a href="https://angular.io/guide/attribute-binding#class-binding"&gt;class binding&lt;/a&gt;. This binds the &lt;code&gt;customClasses&lt;/code&gt; property of the component, which in this example is a space seprated list of CSS classes, to the classes that are actually attached to the DOM element.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;[style]="customStyles"&lt;/code&gt; is a &lt;a href="https://angular.io/guide/attribute-binding#style-binding"&gt;style binding&lt;/a&gt;. This binds the &lt;code&gt;customStyles&lt;/code&gt; property of the component, which contains a semicolon seprated list of CSS styles, to the DOM element.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;(click)="handleClick(txt.value)"&lt;/code&gt; is an &lt;a href="https://angular.io/guide/event-binding"&gt;event binding&lt;/a&gt;. This binds the  &lt;code&gt;handleClick&lt;/code&gt; method on the component with the &lt;code&gt;click&lt;/code&gt; event on the DOM element. So every time the click event fires, our &lt;code&gt;handleClick&lt;/code&gt; method gets invoked. Notice how we have used the template reference variable &lt;code&gt;txt&lt;/code&gt; to access the DOM element here.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Passing data between components
&lt;/h2&gt;

&lt;p&gt;Like we discussed before, a component is responsible for a chunk of our applications' user interface. For better mantainability, components keep largely to themselves and has no idea what's going on outside themselves. But when we compose our application out of a hierarchy of components, we need a way to send data into a component and get data out of that component. For this, Angular provides the &lt;a href="https://angular.io/api/core/Input"&gt;Input&lt;/a&gt; and &lt;a href="https://angular.io/api/core/Output"&gt;Output&lt;/a&gt; decorators:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YemwJe5t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/txbqqmrwnmp8n9zu252q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YemwJe5t--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/txbqqmrwnmp8n9zu252q.png" alt="Components take input and fires output events" width="320" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's create a new component to understand how this works in practice:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng g component baz &lt;span class="nt"&gt;-st&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Replace the generated Baz component code in &lt;code&gt;baz.component.ts&lt;/code&gt; with this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/core&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;selector&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app-baz&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;template&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;`
    &amp;lt;div&amp;gt;
      &amp;lt;p&amp;gt;{{ msg }}&amp;lt;/p&amp;gt;
      &amp;lt;input #txt type="text" /&amp;gt;
      &amp;lt;button (click)="handleClick(txt.value)"&amp;gt;Ok&amp;lt;/button&amp;gt;
    &amp;lt;/div&amp;gt;
  `&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;styles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div{margin: 10px; padding: 5px; width: 200px; border: 1px solid grey}&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;BazComponent&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Default prompt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;nameSelected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

  &lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nameSelected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And use the Baz component from inside the App component like this:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;app-baz&lt;/span&gt; &lt;span class="na"&gt;[msg]=&lt;/span&gt;&lt;span class="s"&gt;"msgIn"&lt;/span&gt; &lt;span class="na"&gt;(nameSelected)=&lt;/span&gt;&lt;span class="s"&gt;"onNameSelected($event)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/app-baz&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;
  Name received from the baz component:&lt;span class="nt"&gt;&amp;lt;br&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;code&amp;gt;&lt;/span&gt;{{ nameOut }}&lt;span class="nt"&gt;&amp;lt;/code&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You need to append the above HTML code to the template in the &lt;code&gt;app.component.ts&lt;/code&gt; file, and the below TypeScript code to the class body.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="nx"&gt;msgIn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Please enter your name&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;nameOut&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;&amp;lt;No Ourput from child component yet&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;onNameSelected&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nameOut&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The Baz component displays a customisable message, reads user text input, and provides an Ok button that when clicked emits a custom event with what the user entered in the text box. Let's see it in action:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tHzywVL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cv8ie6z5qc8k2hwfr0tz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tHzywVL5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/i/cv8ie6z5qc8k2hwfr0tz.png" alt="The baz component takes an input and produces an output" width="640" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The displayed message is customisable by the parent component.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Input&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Default prompt&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;strong&gt;Input&lt;/strong&gt; decorator marks &lt;code&gt;msg&lt;/code&gt; as an input property.&lt;/p&gt;

&lt;p&gt;To the parent component, &lt;code&gt;msg&lt;/code&gt; is "bindable" just like a DOM property:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;app-baz&lt;/span&gt; &lt;span class="na"&gt;[msg]=&lt;/span&gt;&lt;span class="s"&gt;"msgIn"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/app-baz&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The child component fires output events and the parent component binds to these events using the familiar event binding syntax.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;app-baz&lt;/span&gt; &lt;span class="na"&gt;(nameSelected)=&lt;/span&gt;&lt;span class="s"&gt;"onNameSelected($event)"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/app-baz&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The &lt;strong&gt;Output&lt;/strong&gt; decorator is used on a field in the child component to declare that field as an output event.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;  &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Output&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;nameSelected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;EventEmitter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;When the child component has data it needs to ouput, it uses &lt;code&gt;nameSelected&lt;/code&gt; and emit an event with that data as the payload:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;nameSelected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;emit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What's next
&lt;/h2&gt;

&lt;p&gt;The code for our workspace as at the end of this post can be found under the &lt;code&gt;p02&lt;/code&gt; tag in the &lt;a href="https://github.com/nalaka/into-angular"&gt;nalaka/into-angular&lt;/a&gt; repository.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9-wwsHG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/nalaka"&gt;
        nalaka
      &lt;/a&gt; / &lt;a href="https://github.com/nalaka/into-angular"&gt;
        into-angular
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Code for the dev.to series "A tour of Angular for web developers"
    &lt;/h3&gt;
  &lt;/div&gt;
&lt;/div&gt;



&lt;p&gt;In the next post we will see how to create &lt;strong&gt;&lt;em&gt;services&lt;/em&gt;&lt;/strong&gt; that interact with the world outside our component and how to &lt;strong&gt;&lt;em&gt;inject&lt;/em&gt;&lt;/strong&gt; them where they are needed.&lt;/p&gt;

&lt;p&gt;Following this, we will continue our tour by looking at routing, forms, material styling, animation, internationalization, accessibility, testing, and keeping our applications up-to date as Angular itself evovles.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A tour of Angular for web developers</title>
      <dc:creator>Nalaka Jayasena</dc:creator>
      <pubDate>Sat, 22 Aug 2020 08:40:03 +0000</pubDate>
      <link>https://dev.to/nalaka/a-tour-of-angular-for-web-developers-4he1</link>
      <guid>https://dev.to/nalaka/a-tour-of-angular-for-web-developers-4he1</guid>
      <description>&lt;p&gt;This article is the first step in a brief tour of the Angular framework for experienced web developers- specially those coming from another framework like React, Vue, or Ember.&lt;/p&gt;

&lt;p&gt;With a decent grasp of HTML, CSS, TypeScript, HTTP and NodeJS, you should be able to easily follow along, and at the end of the series, have a good idea of how Angular works and how to go about using it to build modern web applications.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This article was last updated on 22nd August 2020.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Preamble&lt;/li&gt;
&lt;li&gt;Web apps&lt;/li&gt;
&lt;li&gt;Web frameworks&lt;/li&gt;
&lt;li&gt;Angular vs React&lt;/li&gt;
&lt;li&gt;A history lesson&lt;/li&gt;
&lt;li&gt;Getting started with Angular&lt;/li&gt;
&lt;li&gt;The layout of an Angular workspace&lt;/li&gt;
&lt;li&gt;An Angular project&lt;/li&gt;
&lt;li&gt;What next?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Preamble
&lt;/h2&gt;

&lt;p&gt;Two years after the initial announcement at &lt;a href="https://www.youtube.com/watch?v=gNmWybAyBHI" rel="noopener noreferrer"&gt;NgConf 2014 Europe&lt;/a&gt;, in the September of 2016, Angular version 2 was finally released. It was a massive overhaul of the framework that greatly improved the internal architecture and overall developer experience. Unfortunately, all those benefits came at a cost.&lt;/p&gt;

&lt;p&gt;Version 2 was not at all backwards compatible with version 1, and at the time, there was no clear upgrade path. Version 2 was, for all practical purposes, a new framework! This caused some developers to jump ship to other frameworks such as React, Vue and Ember, or hold out from upgrading altogether.&lt;/p&gt;

&lt;p&gt;Now contrast this to what happened on the February of 2020 when &lt;a href="https://blog.angular.io/version-9-of-angular-now-available-project-ivy-has-arrived-23c97b63cfa3" rel="noopener noreferrer"&gt;version 9&lt;/a&gt; of Angular was released. Similar to how Angular moved from using the &lt;em&gt;template engine&lt;/em&gt; to &lt;em&gt;view engine&lt;/em&gt; with version 2, the rendering engine was replaced again, with version 9 moving to &lt;em&gt;Ivy&lt;/em&gt; as the default. But this time, the developer experience was quite different. There were no angry tweets or posts about how difficult it is to upgrade- in fact, it was an uneventful, unremarkable, and downright boring upgrade experience.&lt;/p&gt;

&lt;p&gt;So let me start this brief tour by saying that, Angular, with its already comprehensive feature set, great community, and now with a &lt;em&gt;very boring upgrade story&lt;/em&gt; is a framework that gives very little reason for developers to stay away from!&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Web apps
&lt;/h2&gt;

&lt;p&gt;Let's take a step back and look at the big picture behind what we do as web developers.&lt;/p&gt;

&lt;p&gt;A web app, by definition, lives at a particular URL and is loaded by and executed inside a web browser.&lt;/p&gt;

&lt;p&gt;When the browser accesses this URL, it obtains the initial HTML code for the web app. This HTML code links to the CSS, JavaScript, and other asset files it needs.&lt;/p&gt;

&lt;p&gt;The browser loads these files as well and renders the user interface of the web app on to the users' screen. During this process, an in-memory representation of the web page, a.k.a. web document is constructed by the browser and is maintained throughout the execution lifetime of the web app.&lt;/p&gt;

&lt;p&gt;This in-memory representation of the web document is exposed to the web app's JavaScript code for manipulation via the DOM API. The Document Object Model is organized as a tree of nodes and logically sits between our applications' JS code and the view the user sees.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq7341clmce1naax0ifky.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fq7341clmce1naax0ifky.png" alt="Web page, DOM, and web app code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each tag in the HTML file results in a corresponding node in the DOM tree. Each of these nodes correspond to a particular slice of the rendered view. When the user interacts with the view, the browser fires events, which the DOM API allows our JS code to listen to.&lt;/p&gt;

&lt;p&gt;So, a web app is programmed by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HTML code to define the &lt;strong&gt;&lt;em&gt;initial structure&lt;/em&gt;&lt;/strong&gt; of its user interface&lt;/li&gt;
&lt;li&gt;CSS code to define the &lt;strong&gt;&lt;em&gt;initial styling&lt;/em&gt;&lt;/strong&gt; of its user interface&lt;/li&gt;
&lt;li&gt;JavaScript code that:

&lt;ul&gt;
&lt;li&gt;Uses the DOM API to manipulate the structure and styling of the user interface&lt;/li&gt;
&lt;li&gt;Uses other Web APIs for things such as accessing the network and saving data locally&lt;/li&gt;
&lt;li&gt;Implements the actual business logic and deliver value to the user&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Although manipulating the DOM using the DOM API directly is very powerful, it is more convenient to use abstractions on top of that. This is where libraries like jQuery &amp;amp; React, and frameworks like Angular, Vue, and Ember comes in.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Web frameworks
&lt;/h2&gt;

&lt;p&gt;The first library to enjoy widespread adoption was &lt;a href="https://jquery.com" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt;, which  appeared around 2006 and addressed the problem of incompatibilities in how the Web APIs were implemented across the major web browsers.   It also gave a simple, elegant API on top of the original DOM API for accessing and manipulating the DOM. &lt;/p&gt;

&lt;p&gt;The next challenge was to have an easier way for our web apps'  data and logic, typically organized as JS classes and or functions, to drive the user interface behind the DOM API. This question was addressed by multiple efforts that started to appear around 2010- such as, &lt;a href="https://knockoutjs.com" rel="noopener noreferrer"&gt;Knockout.js&lt;/a&gt;, &lt;a href="https://backbonejs.org" rel="noopener noreferrer"&gt;Backbone.js&lt;/a&gt;, &lt;a href="https://sproutcore.com" rel="noopener noreferrer"&gt;SproutCore&lt;/a&gt;, and &lt;a href="https://angularjs.org" rel="noopener noreferrer"&gt;AngularJS&lt;/a&gt;.  These were followed by &lt;a href="https://emberjs.com" rel="noopener noreferrer"&gt;EmberJS&lt;/a&gt; which sprang out from SproutCore in 2011 December.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://reactjs.org/" rel="noopener noreferrer"&gt;React&lt;/a&gt;  launched in 2013 with its virtual DOM and component based approach to UI composition that challenged the mostly MVC based approaches of its predecessors.  And &lt;a href="https://vuejs.org/" rel="noopener noreferrer"&gt;Vue.js&lt;/a&gt; appeared in 2014 combining features of both AngularJS and React.&lt;/p&gt;

&lt;p&gt;In 2016 &lt;a href="https://angular.io" rel="noopener noreferrer"&gt;Angular&lt;/a&gt; was released, a complete reboot of Angular, which ditched the MVC based approach of AngularJS in favor of a component based approach.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Angular vs React
&lt;/h2&gt;

&lt;p&gt;Angular is often compared with React. &lt;/p&gt;

&lt;p&gt;The first thing to note is that React is a &lt;em&gt;library&lt;/em&gt; for building user interfaces whereas Angular is a &lt;em&gt;framework&lt;/em&gt; for building applications. Given that applications certainly need user interfaces, it follows that Angular covers  a much bigger scope than React. This unfortunately also means that Angular has a much bigger learning curve than React so developers are quicker to get productive in React than in Angular. So for simple apps, React seems to be a better choice.&lt;/p&gt;

&lt;p&gt;But the proper comparison is to compare Angular with &lt;em&gt;React core + React ecosystem&lt;/em&gt;. With React, most of the pieces that Angular provides as part of the framework needs to be picked and chosen from a large buffet of community offerings. This is a good and a bad thing. It is good because it gives more options to the developer so she can put together a highly customized solution. And it is bad for exactly the same reason. Too much choice is often problematic, specially for those beginners who looked at Angular, thought it had too much of a learning curve, gave up and instead picked React. They breeze through the core React concepts in a few weeks and then realize that building their apps requires quite a few more tools than what the React library provides.&lt;/p&gt;

&lt;p&gt;So for complex apps, specially CRUD style enterprisy ones, arguably, Angular has a &lt;strong&gt;&lt;em&gt;smaller total learning curve&lt;/em&gt;&lt;/strong&gt; and a better return on intellectual investment than React.&lt;/p&gt;

&lt;p&gt;Angular is a well architectured comprehensive application framework. So as you build bigger applications and maintain them for longer, you realize that the upfront learning cost of Angular is offset by the developer productivity that Angular continues to give over the full lifecycle of the web application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Once developers get through the core concepts that underlies the Angular framework, they realize that the going gets much more easier and that they have in their possession a much more powerful toolbox with a set of cohesive tools to wield at many application development challenges.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That was how Angular compares to React at a framework level. There is also a fundamental difference in the way the UI library parts of the two frameworks handle DOM manipulation.&lt;/p&gt;

&lt;p&gt;Though both Angular and React puts components front and center, as the building block for composing user interfaces out of, React uses what is known as a virtual DOM for manipulating the DOM whereas Angular works with the real DOM.&lt;/p&gt;

&lt;p&gt;The virtual DOM is basically an in-memory representation of the real DOM so that when detecting changes, React does not have to touch the real DOM. That makes change detection faster.&lt;/p&gt;

&lt;p&gt;Angular has adopted a totally different approach where the Angular compiler augments our app code with framework code. Then this hybrid code operates directly on the real DOM. The extra code is responsible for binding data between our "apps' objects" and "DOM objects" as well as handling DOM events from inside our apps' methods. The compiler tree-shakes unused framework and application code so as to produce leaner code bundles.&lt;/p&gt;

&lt;p&gt;Both approaches have pros and cons- and each framework inspires the other to innovate. So assertions about each framework that was true few years ago may not hold today. As developers, our responsibility is to understand the task at hand and the pick the right tool for that particular job.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  A history lesson
&lt;/h2&gt;

&lt;p&gt;On 2020 October, Angular will be 10 years old. Over the last decade, Angular has helped transform the way we architecture and build web applications and in turn had transformed itself in lockstep with the evolution of the web platform. Let's take a look back at how Angular evolved over the years.&lt;/p&gt;

&lt;p&gt;AngularJS was &lt;a href="http://misko.hevery.com/2009/09/28/hello-world-angular-is-here/" rel="noopener noreferrer"&gt;announced by Miško Hevery&lt;/a&gt; in 2009 and version 1 was released in 2010. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpk89jwl7321ia1jaxzfx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpk89jwl7321ia1jaxzfx.png" alt="Angular announcement by Miško Hevery"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It came into a world looking for a better way to build web applications- and it really took off.&lt;/p&gt;

&lt;p&gt;When v2 was released in 2016 September. It was a complete rewrite and was branded Angular instead of AngularJS. Most people felt that it was a completely different framework that happened to be done by the same team under almost the same name. In some senses it was, for example the &lt;strong&gt;&lt;em&gt;template engine&lt;/em&gt;&lt;/strong&gt; at the  core of Angular was replaced by the &lt;strong&gt;&lt;em&gt;view engine&lt;/em&gt;&lt;/strong&gt; and the MVC architecture was replaced with a component based one.&lt;/p&gt;

&lt;p&gt;There was no v3 of Angular because the Angular Router for Angular v2 had already been released as v3. Angular v4 was released 2017 March and  v5 in  2017 November.&lt;/p&gt;

&lt;p&gt;Angular v6 was released 2018 May. It focused on synchronization of the Angular toolchain- core, compiler, CLI, material, CDK, and a commitment was given to the community to keep things in sync going forward. A way to help users update their applications to newer versions of Angular was introduced in the form of a new CLI command called &lt;code&gt;update&lt;/code&gt;. Another new CLI command &lt;code&gt;add&lt;/code&gt; was introduced to help generate common application parts such as components.&lt;/p&gt;

&lt;p&gt;Angular v7, released in 2018 October, introduced &lt;strong&gt;&lt;em&gt;schematics&lt;/em&gt;&lt;/strong&gt;, a mechanism for customizing the files CLI generates with the &lt;code&gt;add&lt;/code&gt; command.&lt;/p&gt;

&lt;p&gt;In 2019 May,  Angular v8 introduced &lt;strong&gt;&lt;em&gt;differential loading&lt;/em&gt;&lt;/strong&gt;, which allowed the generation of smaller apps (often 7 to 20 percent smaller) by creating two separate bundles- one for evergreen browsers and one for legacy browsers. Version 8 also introduced &lt;strong&gt;&lt;em&gt;builders&lt;/em&gt;&lt;/strong&gt;, which allowed the customization of the tools used and the order in which they are run by the compiler.&lt;/p&gt;

&lt;p&gt;Angular v8 was released in 2020 March. The new rendering engine, &lt;strong&gt;&lt;em&gt;Ivy&lt;/em&gt;&lt;/strong&gt;, that replaces the template engine used since v2 was available as an opt-in. Ivy was subsequently made the default for Angular at version 9, which was released in 2020 February.&lt;/p&gt;

&lt;p&gt;Version 10, that came out on 2020 June, is the latest major release. It introduced few more features aimed at producing leaner and more maintainable Angular apps. For example, the CLI now warns when a dependency is packaged with CommonJS.  A &lt;code&gt;strict&lt;/code&gt; option for the  &lt;code&gt;ng new&lt;/code&gt; CLI command was added which enables strict mode in TypeScript and strict type checking in templates. The apps are now configured as side effect free, which makes them more tree shakable thus leading to smaller bundles.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting started with Angular
&lt;/h2&gt;

&lt;p&gt;With a current release of NodeJS already installed in your system, install the &lt;code&gt;@angular/cli&lt;/code&gt; package globally:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @angular/cli
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should be able to access the Angular CLI with &lt;code&gt;ng&lt;/code&gt; command: Try running &lt;code&gt;ng version&lt;/code&gt; and &lt;code&gt;ng help&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Open a shell and change directory to wherever you save your coding projects and use the &lt;code&gt;ng new&lt;/code&gt; command to generate a new Angular workspace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng new into-angular &lt;span class="se"&gt;\&lt;/span&gt;
        &lt;span class="nt"&gt;--strict&lt;/span&gt; &lt;span class="nt"&gt;--create-application&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"false"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An &lt;code&gt;into-angular&lt;/code&gt; directory gets created with the workspace files and a Git repository gets initialized.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://angular.io/guide/strict-mode" rel="noopener noreferrer"&gt;strict&lt;/a&gt; option, introduced in Angular 10, enforces a set of best practices such as stronger type checking and making parts of the application self-contained and side effect free.&lt;/p&gt;

&lt;p&gt;Let's add a web application project to our workspace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng generate application hello &lt;span class="se"&gt;\&lt;/span&gt;
       &lt;span class="nt"&gt;--strict&lt;/span&gt;  &lt;span class="nt"&gt;--inline-template&lt;/span&gt;  &lt;span class="nt"&gt;--inline-style&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change into the generated workspace directory and use the &lt;code&gt;ng serve&lt;/code&gt; command to build the &lt;code&gt;hello&lt;/code&gt; project and run in the development server with live reload enabled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;into-angular
ng serve hello &lt;span class="nt"&gt;--open&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;--open&lt;/code&gt; option opens the default web browser at the URL exposed by the development server. &lt;/p&gt;

&lt;p&gt;We can run the unit tests with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng &lt;span class="nb"&gt;test &lt;/span&gt;hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the end-to-end tests with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng e2e hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can do a production build with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng build hello &lt;span class="nt"&gt;--prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The production build is generated in the &lt;code&gt;into-angular/dist/hello&lt;/code&gt; folder, and the output sizes are quite small- no unreasonable overhead from the framework!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; 535B   index.html
   0B   styles.3ff695c00d717f2d2a11.css
 1.5K   runtime.e227d1a0e31cbccbf8ec.js
  36K   polyfills.9e86b32c42185429d576.js
 102K   main.77129eaa6e421d8e7131.js
  13K   3rdpartylicenses.txt
 948B   favicon.ico
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To serve the production build locally, install the &lt;code&gt;serve&lt;/code&gt; utility and "serve" this directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; serve

serve into-angular/dist/hello
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The layout of an Angular workspace
&lt;/h2&gt;

&lt;p&gt;The generated Angular workspace directory contains configuration files that applies to all projects.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqsc2trry3p53fhugamht.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fqsc2trry3p53fhugamht.png" alt="Directory layout of an Angular workspace"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;All projects in a workspace share NPM dependencies. So even if you have ten projects inside the &lt;code&gt;projects&lt;/code&gt; directory, you would have only one &lt;code&gt;node_modules&lt;/code&gt; directory- the one at the workspace level.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;tsconfig.base.json&lt;/code&gt; declares the base options for the TypeScript compiler. These get extended by project level tsconfig files. &lt;/p&gt;

&lt;p&gt;The workspace level &lt;code&gt;tsconfig.json&lt;/code&gt; file is for code editors to pickup . So is the &lt;code&gt;.editorconfig&lt;/code&gt; file, which declares coding style options like indenting, quotes, brackets, tabs/spaces.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;angular.json&lt;/code&gt; file is where we configure the behavior of the Angular compiler.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"defaultProject"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"hello"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"newProjectRoot"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"projects"&lt;/span&gt;&lt;span class="err"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"projects"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"projectType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"application"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"root"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"projects/hello"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"sourceRoot"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"projects/hello/src"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prefix"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"app"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"schematics"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"architect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"builder"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"@angular-devkit/build-angular:browser"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"options"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"configurations"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="nl"&gt;"production"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"serve"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"e2e"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{},&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since the &lt;code&gt;defaultProject&lt;/code&gt; is set to &lt;em&gt;hello&lt;/em&gt;, in &lt;code&gt;ng&lt;/code&gt; commands, we can drop the project name and still have the command act on the default &lt;code&gt;hello&lt;/code&gt; project. So, we can just do a &lt;code&gt;ng serve&lt;/code&gt; and get the &lt;em&gt;hello&lt;/em&gt; project served.&lt;/p&gt;

&lt;p&gt;In our &lt;code&gt;hello&lt;/code&gt; project, we have the &lt;code&gt;projectType&lt;/code&gt; set to application. The other option here is &lt;em&gt;library&lt;/em&gt;. Later in our tour, we will see how to create a library project and reuse it in multiple application projects. &lt;/p&gt;

&lt;p&gt;Soon we will be generating components and other directives- these have a &lt;em&gt;selector&lt;/em&gt; that is used inside HTML templates to activate the directive. The string we specify in the &lt;code&gt;prefix&lt;/code&gt; option is used as a prefix for the selector when we generate the directive with &lt;code&gt;ng generate directive&lt;/code&gt; or &lt;code&gt;ng generate component&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Schematics&lt;/strong&gt; are the blueprints for the artifacts that the Angular CLI generates with &lt;code&gt;ng generate&lt;/code&gt; command- applications, libraries, components, generic directives, services, pipes, and so on. Options for these go under the &lt;code&gt;schematics&lt;/code&gt; section. The &lt;code&gt;architect&lt;/code&gt; section is for configuring the Angular CLI build pipeline. Angular let's us customize both of these aspects- what the various generators output (with custom schematics) and what the build pipeline does (with custom builders). Later in this tour, we will see how!&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  An Angular project
&lt;/h2&gt;

&lt;p&gt;The generated web application project, &lt;em&gt;hello&lt;/em&gt;, looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feifxvjijtb3q8aa0bro6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Feifxvjijtb3q8aa0bro6.png" alt="Directory layout of an Angular project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;.browserslistrc&lt;/code&gt; file declares browsers supported by this project. Angular uses this information to adjust the CSS/JS output of the compiler.&lt;/p&gt;

&lt;p&gt;Angular uses &lt;a href="https://jasmine.github.io/" rel="noopener noreferrer"&gt;Jasmine&lt;/a&gt; for writing unit tests and &lt;a href="https://karma-runner.github.io/" rel="noopener noreferrer"&gt;Karma&lt;/a&gt;,  configured with the&lt;code&gt;karma.conf.js&lt;/code&gt; file,  for running them.&lt;/p&gt;

&lt;p&gt;There are two tsconfig files- one for the application code, and one for the unit test code. These are for configuring the TypeScript compiler. The &lt;code&gt;tslint.json&lt;/code&gt; file configures the TypeScript linter, TSLint. All three files extend their parents from the workspace directory.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;src&lt;/code&gt; folder contains all the source code for the application including unit tests. The &lt;code&gt;e2e&lt;/code&gt; folder contains all the end to end tests. Let's dive into what they contain.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuirrx2na8z7oqzvb3smh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fuirrx2na8z7oqzvb3smh.png" alt="Layout of the e2e directory of an Angular web application project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.protractortest.org" rel="noopener noreferrer"&gt;Protractor&lt;/a&gt;, configured with  &lt;code&gt;protractor.config.js&lt;/code&gt;, is used for writing end to end tests. The &lt;code&gt;app.po.ts&lt;/code&gt; file is a "Page Object" for the our app's landing page.  This has convenience methods for use in the actual end to end test file, in this case, &lt;code&gt;app.e2e-spec.ts&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftyk3m0tisaycx09alw9t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ftyk3m0tisaycx09alw9t.png" alt="Layout of the src directory of an Angular web application project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;index.html&lt;/code&gt; file is the main template. This is where the root component of our app's component hierarchy gets referenced. Entry point for application code is the &lt;code&gt;main.ts&lt;/code&gt; file. For running unit tests, the entry point is the &lt;code&gt;test.ts&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Styles shared across the app are in the &lt;code&gt;styles.css&lt;/code&gt; file. Later we will see that components can define their own private styles.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;app&lt;/code&gt; directory is named after the name of the &lt;em&gt;code module&lt;/em&gt; it holds- in this case, &lt;em&gt;app&lt;/em&gt;. The &lt;code&gt;AppModule&lt;/code&gt; class is found in &lt;code&gt;app.module.ts&lt;/code&gt;.  This is the default module for holding our applications’ parts- components, other directives, services, pipes and so on. As we build bigger applications we will need more modules so that we can divide up the app into more manageable sections and load each section lazily when needed.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;app.component.ts&lt;/code&gt; declares the &lt;code&gt;AppComponent&lt;/code&gt; and  &lt;code&gt;app.component.spec.ts&lt;/code&gt; contains unit tests for it. &lt;code&gt;AppComponent&lt;/code&gt; sits at the root of our apps' component hierarchy. This is the component that get referenced in &lt;code&gt;index.html&lt;/code&gt; causing our whole app to recursively get loaded.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What next?
&lt;/h2&gt;

&lt;p&gt;In the next article we will take a closer look at the primary building block of an angular application, the &lt;strong&gt;&lt;em&gt;component&lt;/em&gt;&lt;/strong&gt;. Then we will see how to create &lt;strong&gt;&lt;em&gt;services&lt;/em&gt;&lt;/strong&gt; that interact with the world outside our component and how to &lt;strong&gt;&lt;em&gt;inject&lt;/em&gt;&lt;/strong&gt; them where they are needed. On subsequent articles, we will continue our tour by looking at routing, forms, material styling, animation, internationalization, accessibility, testing, and keeping the application up-to date as Angular itself improves.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

</description>
      <category>angular</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>A Software development setup on Apple Mac</title>
      <dc:creator>Nalaka Jayasena</dc:creator>
      <pubDate>Wed, 12 Aug 2020 18:07:05 +0000</pubDate>
      <link>https://dev.to/nalaka/a-software-development-setup-on-apple-mac-32po</link>
      <guid>https://dev.to/nalaka/a-software-development-setup-on-apple-mac-32po</guid>
      <description>&lt;p&gt;This is my current setup- sharing for my future self and anyone else that stumbles on here.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
The bare necessities &lt;/li&gt;
&lt;li&gt;JavaScript&lt;/li&gt;
&lt;li&gt;Rust&lt;/li&gt;
&lt;li&gt;Java&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  The bare necessities
&lt;/h2&gt;

&lt;p&gt;The &lt;em&gt;Command Line Developer Tools&lt;/em&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;xcode-select &lt;span class="nt"&gt;--install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The default installation location is &lt;code&gt;/Library/Developer/CommandLineTools&lt;/code&gt;, you can double check with &lt;code&gt;xcode-select -p&lt;/code&gt;. Check the contents of the  &lt;code&gt;usr/bin&lt;/code&gt; sub-directory for all the tools that this gives you.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://brew.sh/"&gt;Homebrew&lt;/a&gt; package manager.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.iterm2.com/"&gt;iTerm 2&lt;/a&gt; -  a great replacement for the built-in terminal app. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://ohmyz.sh/"&gt;Oh My Zsh&lt;/a&gt; - spices up the shell.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://code.visualstudio.com/"&gt;Visual Studio Code&lt;/a&gt; - code editor &lt;/p&gt;

&lt;p&gt;The  development editions of Chrome and Firefox web browsers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.google.com/chrome/dev/"&gt;Google Chrome for Developers&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.mozilla.org/en-US/firefox/developer/"&gt;Firefox Developer Edition&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note taking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://evernote.com/"&gt;Evernote&lt;/a&gt; - great for taking a quick note on the phone and picking up from the computer&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://typora.io/"&gt;Typora&lt;/a&gt; - surprisingly good markdown editor&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Communication and media:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://www.videolan.org/vlc/"&gt;VLC Media Player&lt;/a&gt; - plays 'most anything thrown at it&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.skype.com"&gt;Skype&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And some miscellaneous utilities:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://mac.eltima.com/download-manager.html"&gt;Folx Free Edition&lt;/a&gt; - for file downloads&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.paragon-software.com/home/ntfs-mac/"&gt;NTFS for Mac&lt;/a&gt; - for working with disks formatted for Windows with NTFS&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  JavaScript
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://volta.sh/"&gt;Volta&lt;/a&gt; is great for managing JS command line tools.&lt;/p&gt;

&lt;p&gt;Install with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl https://get.volta.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later when Volta needs to be updated, repeat the same command.&lt;/p&gt;

&lt;p&gt;Install Node.js&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;volta &lt;span class="nb"&gt;install &lt;/span&gt;node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Install any JS tools from NPM with &lt;code&gt;volta install package-name&lt;/code&gt; - e.g.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;volta &lt;span class="nb"&gt;install &lt;/span&gt;serve          &lt;span class="c"&gt;# Serve a local directory over HTTP&lt;/span&gt;
volta &lt;span class="nb"&gt;install &lt;/span&gt;prettier       &lt;span class="c"&gt;# Code formatter&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later, a tool can be updated by repeating the install command.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Rust
&lt;/h2&gt;

&lt;p&gt;Use the &lt;a href="https://www.rust-lang.org/learn/get-started"&gt;Rustup&lt;/a&gt; script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;--proto&lt;/span&gt; &lt;span class="s1"&gt;'=https'&lt;/span&gt; &lt;span class="nt"&gt;--tlsv1&lt;/span&gt;.2 &lt;span class="nt"&gt;-sSf&lt;/span&gt; https://sh.rustup.rs | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Update with &lt;code&gt;rustup update&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Self uninstallation is supported with &lt;code&gt;rustup self uninstall&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Java
&lt;/h2&gt;

&lt;p&gt;Download the &lt;code&gt;.dmg&lt;/code&gt; installer for the latest stable Java SDK from &lt;a href="https://www.oracle.com/java/technologies/javase-downloads.html"&gt;Oracle&lt;/a&gt; and run.&lt;/p&gt;

&lt;p&gt;Back to TOC.&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>devtools</category>
      <category>mac</category>
    </item>
  </channel>
</rss>
