<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ angular2 - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ angular2 - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Fri, 29 May 2026 23:04:45 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/angular2/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Angular vs React: Which One to Choose for Your App ]]>
                </title>
                <description>
                    <![CDATA[ A precise side-by-side comparison of general and technical aspects of Angular and React There are so many articles titled “Angular vs React”, “React vs Angular”, “Angular or React” – it is a miracle you opened this one! What these articles are missin... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/angular-vs-react-what-to-choose-for-your-app-2/</link>
                <guid isPermaLink="false">66be14af9f6cdc38e7dec50b</guid>
                
                    <category>
                        <![CDATA[ Angular ]]>
                    </category>
                
                    <category>
                        <![CDATA[ angular 5 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ angular2 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ angular6 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ angular8 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Angular ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Oleh Romanyuk ]]>
                </dc:creator>
                <pubDate>Tue, 08 Oct 2019 13:49:33 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/10/react-vs-angular.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <h3 id="heading-a-precise-side-by-side-comparison-of-general-and-technical-aspects-of-angular-and-react">A precise side-by-side comparison of general and technical aspects of Angular and React</h3>
<p>There are so many articles titled “Angular vs React”, “React vs Angular”, “Angular or React” – it is a miracle you opened this one! What these articles are missing, however, is a precise <strong>side-by-side comparison</strong> of Angular vs React. </p>
<blockquote>
<p>So this is what I am going to do in this blog post: to place <a target="_blank" href="https://keenethics.com/tech-front-end-react">React</a> and <a target="_blank" href="https://keenethics.com/tech-front-end-angular">Angular</a> in direct juxtaposition. We're going to review and contrast the two JavaScript frameworks and look at each possible characteristic to make sure we don't miss even a single piece of data. </p>
</blockquote>
<p>In the end, I am not going to tell you which technology to choose. But I will give you enough food for thought for you to choose the technology that suits you and your project best.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2024/08/Angular_React_comparison-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/2PpsrJKGRiYFYhCXh9NcfM/c43b9b24509d459ec94d7f7bb6ce207a/search__1_.png?h=300" alt="search (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-1-brief-overview">1. Brief Overview</h2>
<h3 id="heading-react">React</h3>
<p>React is a JavaScript library for UI development. It is managed by Facebook and an open-source community of developers.</p>
<p>The framework was introduced in May 2013.</p>
<p>The latest updates were released on August 8th, 2019 – just over a month ago.</p>
<h3 id="heading-angular">Angular</h3>
<p>Angular is an open-sourced JavaScript framework for web and mobile development. It is TypeScript-based and managed by Google’s Angular Team and the Angular developer community. </p>
<p>Launched in September 2016, Angular (also known as Angular 2.0) is a complete rewrite of AngularJS (Angular 1.0), which was introduced in 2010. </p>
<p>There have been six versions of Angular already, and the latest release took place on August 28th, 2019 – almost three weeks ago.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/26X0F8SysU9aRODLpiTS8T/6d17ff52d723a3d8b34b54a4f53f6e34/internet__1_.png?h=300" alt="internet (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-2-universality">2. Universality</h2>
<h3 id="heading-react-1">React</h3>
<p>React is a framework used in both web and mobile development. However, for mobile development, it needs to be incorporated with Cordova. Moreover, for mobile development, there is an additional framework – React Native.</p>
<p>React can be used to build both single-page and multiple-page web applications.</p>
<h3 id="heading-angular-1">Angular</h3>
<p>Angular is suitable for both web and mobile development. In mobile development, however, a great share of work is done by Ionic. Furthermore, similarly to React, Angular has an additional mobile development framework. The counterpart of React Native is NativeScript. </p>
<p>Angular can also be used for both single- and multiple-page web apps.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/7EP4F57YmLWZvF7OO0iDTX/b7ba3aacd67d576f1fcc49ba78478916/success__1_.png?h=300" alt="success (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-3-self-sufficiency">3. Self-Sufficiency</h2>
<h3 id="heading-react-2">React</h3>
<p>React is a framework for UI development, so apps written with React need additional libraries to be used. For instance, Redux, React Router, or Helmet optimize the processes of state management, routing, and interaction with the API. Such functions as data binding, component-based routing, project generation, form validation, or dependency injection require additional modules or libraries to be installed.</p>
<h3 id="heading-angular-2">Angular</h3>
<p>Angular is a full-fledged framework for software development, which usually does not require additional libraries. All the above-mentioned functions – data binding, component-based routing, project generation, form validation, and dependency injection – can be implemented with the means of Angular package.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/pFVFckO96mf60jYoDLsXA/df1d17d0c516c24b906feacc66a36b2d/open-book.png?h=300" alt="open-book" width="256" height="256" loading="lazy"></p>
<h2 id="heading-4-learning-curve">4. Learning Curve</h2>
<h3 id="heading-react-3">React</h3>
<p>React is minimalistic: no dependency injection, no classic templates, no overly complicated features. The framework will be quite simple to understand if you already know JavaScript well. </p>
<p>However, it takes quite some time to learn how to set up a project because there is no predefined project structure. You also need to learn the Redux library, which is used in more than half of React applications for state management. Constant framework updates also require additional effort from the developer. Furthermore, there are quite a lot of best practices in React, which you will need to learn to do things right.</p>
<h3 id="heading-angular-3">Angular</h3>
<p>Angular itself is a huge library, and learning all the concepts associated with it will take much more time than in the case of React. Angular is more complex to understand, there is a lot of unnecessary syntax, and component management is intricate. Some complicated features are embedded into the framework core, which means that the developer cannot avoid learning and using them. Moreover, there are a lot of ways of solving a single issue. </p>
<p>Although TypeScript closely resembles JavaScript, it also takes some time to learn. Since the framework is constantly updated, the developer needs to put some extra learning effort.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/3UoGpyTMCV8CGu1Z4kjpse/d32f947e97c9ca59b8d06ffa3cbcab5e/users__1_.png?h=300" alt="users (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-5-community">5. Community</h2>
<h3 id="heading-react-4">React</h3>
<p>React framework is one of the most popular JS frameworks worldwide, and the community supporting and developing it is huge.</p>
<p>Working with React, you have to be a continuous learner since the framework is often updated. While the community tries to go forward with the latest documentation as swiftly as possible, keeping up with all the changes is not that easy. Sometimes, there may be a lack of documentation, but the issue is often solved by the community support on thematic forums. </p>
<p>React is actively used by such companies as Facebook, Twitter, Netflix, Airbnb, PayPal, The New York Times, Yahoo, Walmart, Uber, and Microsoft.</p>
<h3 id="heading-angular-4">Angular</h3>
<p>Angular is less admired than React and faces a lot of skepticism, partially because of the unpopularity of Angular 1.0. Developers used to dismiss the framework as an overly complicated one as it required a lot of time to be spent learning. However, this framework has been developed by Google, which works in favor of Angular’s credibility. </p>
<p>Google provides the long-term support of the framework and constantly improves it. However, the updates are so fast that the documentation often falls behind. </p>
<p>Angular is used by such companies as McDonald’s, AT&amp;T, HBO, Apple, Forbes, Adobe, Nike, and Microsoft as well.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/42G1ot0FKIiLsLEss57U7C/afa7f06c694c2481af01923ade2c1f90/settings__1_.png?h=300" alt="settings (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-6-performance">6. Performance</h2>
<h3 id="heading-react-5">React</h3>
<p>React’s performance is greatly improved with the introduction of the virtual DOM. Since all virtual DOM trees are lightweight and built on server, the load on browser is reduced. Furthermore, since the data-binding process is unidirectional, bindings are not assigned watchers as in the case of Angular. Respectively, no additional workload is created.</p>
<h3 id="heading-angular-5">Angular</h3>
<p>Angular performs worse, especially in the case of complex and dynamic web apps. </p>
<p>The performance of Angular apps is negatively affected by bidirectional data-binding. Each binding is assigned a watcher to track changes, and each loop continues until all the watchers and associated values are checked. Because of this, the more bindings you have, the more watchers are created, and the more cumbersome the process becomes. </p>
<p>However, the most recent update of Angular has greatly improved its performance, and it does not lose to React anymore. Moreover, the size of an Angular application is slightly smaller than the size of a React app.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/LCPTXwhsTKQ4YasbWaJBg/3ecbcedd4687993fcca72086a16abc0f/menu__1_.png?h=300" alt="menu (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-7-language">7. Language</h2>
<h3 id="heading-react-6">React</h3>
<p>React is based on JavaScript ES6+ combined with JSX script. JSX is an extension for syntax, which makes a JavaScript code resemble that written in HTML. This makes the code easier to understand, and typos are easier to spot. For the JSX code to be compiled in a browser, React is augmented with Babel – a code translation tool.</p>
<h3 id="heading-angular-6">Angular</h3>
<p>Angular can use JavaScript or TypeScript, which is a superset of JS developed specifically for larger projects. TypeScript is more compact than JavaScript, the code is easier to navigate, and typos are easily spotted. Code refactoring process also becomes simpler and faster.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/34RQEkHFyn2MwWWbUxVwyx/d621c2de5692fb4b686b3702472676ab/layers__2_.png?h=300" alt="layers (2)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-8-app-structure">8. App Structure</h2>
<h3 id="heading-react-7">React</h3>
<p>The structure of React provides developers with the freedom to choose. There is no “the only right structure” for a React app. However, the necessity to design the app structure at the beginning of each project makes it more difficult and longer to start.</p>
<p>Besides, React offers only View layer, while Model and Controller are added with the usage of other libraries.</p>
<p>The architecture of a React app is component-based. The code is made of React components, which are rendered with React DOM library and directed in two ways: functional (with a function that returns JSX)...</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Hello</span>(<span class="hljs-params">props</span>)</span>{
<span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>Hello {props.name}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
}
</code></pre>
<p>...and class-based (with ES6 classes).</p>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Hello</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
render() {
<span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello, {this.props.name}<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span></span>;
}
</code></pre>
<h3 id="heading-angular-7">Angular</h3>
<p>The structure of Angular is fixed and complex, suitable for experienced developers.</p>
<p>Angular is based on three layers – Model, Controller, and View. An object responsible for the Model is initialized by the Controller and displayed with the View.</p>
<p>The application code consists of different Angular components, each being written in four separate files: a TypeScript to implement the component, an HTML file to define the view, a CSS file to define the stylistic features, and a special file for testing purposes. Links to these files are written in the app directive, which displays the structural logic of the app. Respectively, Angular components are also reusable.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { Component } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
@Component({
<span class="hljs-attr">selector</span>: <span class="hljs-string">'my-app'</span>,
<span class="hljs-attr">templateUrl</span>: <span class="hljs-string">'./app.component.html'</span>,
<span class="hljs-attr">styleUrls</span>: [<span class="hljs-string">'./app.component.css'</span>]
})
<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppComponent</span> </span>{ }
</code></pre>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/1jnhjOLhvVfIJpf1JjAFlO/e14f81b5efdca246c0d2beab0e49c2f0/app__1_.png?h=300" alt="app (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-9-ui-components">9. UI Components</h2>
<h3 id="heading-react-8">React</h3>
<p>UI tools for React are developed by the community. There are a lot of free and paid UI components on the React portal. To use material design components in React, you would have to install an additional library – Material-UI Library &amp; Dependencies.</p>
<h3 id="heading-angular-8">Angular</h3>
<p>Angular has a built-in Material toolset, and it offers a variety of pre-built material design components. There are various buttons, layouts, indicators, pop-ups, and form controls. Because of this, UI configuration becomes simpler and faster.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/27zKcdqY3mOnzT5p8vrQbC/e987f42102e8875d0f7714d8db3288f8/file__1_.png?h=300" alt="file (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-10-directives">10. Directives</h2>
<h3 id="heading-react-9">React</h3>
<p>In React, templates and logic are explained in one place – at the end of the component. It allows the reader to quickly grasp the meaning of the code even if they do not know the syntax.</p>
<h3 id="heading-angular-9">Angular</h3>
<p>In Angular, each template is returned with an attribute – a directive of how the object has to be set. The syntax of Angular directives is complex and sophisticated, which makes it incomprehensible for a reader without any experience in working with this technology.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/4I2aqTboict17ysz5yGD4n/5a7fc19e15889f42b7561d34b18edae9/controls__1_.png?h=300" alt="controls (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-11-state-management">11. State Management</h2>
<h3 id="heading-react-10">React</h3>
<p>In React, each component has its own state. A React developer can create special components for holding the state of the entire application or a particular part of it. The major disadvantage here consists in the fact that the global state needs to be stored in multiple different parts of the app with data being manually passed around different component tree levels.</p>
<pre><code class="lang-js"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Clock</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
  <span class="hljs-keyword">constructor</span>(props) {
    <span class="hljs-built_in">super</span>(props);
   <span class="hljs-built_in">this</span>.state = {<span class="hljs-attr">date</span>: <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>()};
 }
  render() {
    <span class="hljs-keyword">return</span> (
      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Hello world!<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Now is {this.state.date.toLocaleTimeString()}.<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
    );
  }
}
</code></pre>
<p>To solve this problem, there is a special state management library – Redux. The idea of it is that the global state is represented as a single stateful object, which is altered in different parts of the app with the help of reducers – special Redux functions.</p>
<p>Another solution is offered by the state management library MobX. Unlike Redux with the global state stored in a single immutable stateful object, MobX offers storing only the minimal required state, while the rest of it can be derived.</p>
<h3 id="heading-angular-10">Angular</h3>
<p>In Angular, component data is stored in component properties. Parent components pass data through to children ones. State changes in some parts can be identified and recalculated, but in a large app, it can cause a multi-directional tree series of updates, which will be difficult to track. The features can be improved with the help of state management libraries, such as NgRx or RxJS , which would make sure that the data flow is unidirectional.</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HeroListComponent</span> <span class="hljs-title">implements</span> <span class="hljs-title">OnInit</span> </span>{
  <span class="hljs-attr">heroes</span>: Hero[];
  selectedHero: Hero;
  <span class="hljs-keyword">constructor</span>(private service: HeroService) { }
  ngOnInit() {
    <span class="hljs-built_in">this</span>.heroes = <span class="hljs-built_in">this</span>.service.getHeroes();
  }
  selectHero(hero: Hero) { <span class="hljs-built_in">this</span>.selectedHero = hero; }
}
</code></pre>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/1FrBshReFNJB1yDkeNVBPr/091aac131dccf0267061a450f76fb897/network__1_.png?h=300" alt="network (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-12-dependency-injection">12. Dependency Injection</h2>
<h3 id="heading-react-11">React</h3>
<p>React does not fully support dependency injection as it does not fully comply with the idea of functional programming and data immutability. Instead, it has a global state for all components.</p>
<h3 id="heading-angular-11">Angular</h3>
<p>The greatest advantage of Angular rests in the fact that, unlike React, it supports dependency injection. Therefore, Angular allows having different lifecycles for different stores.</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> { Injectable } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
<span class="hljs-keyword">import</span> { HEROES } <span class="hljs-keyword">from</span> <span class="hljs-string">'./mock-heroes'</span>;
@Injectable({
  <span class="hljs-comment">// we declare that this service should be created</span>
  <span class="hljs-comment">// by the root application injector.</span>
  <span class="hljs-attr">providedIn</span>: <span class="hljs-string">'root'</span>,
})
<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">HeroService</span> </span>{
  getHeroes() { <span class="hljs-keyword">return</span> HEROES; }
}
</code></pre>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/4FJFtvDwvmQdgsCUx5MYOO/b87ee7b57de5908ef20405e95b707959/unlink__1_.png?h=300" alt="unlink (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-13-data-binding">13. Data Binding</h2>
<h3 id="heading-react-12">React</h3>
<p>Data binding stands for the data synchronization process between Model and View. React should be augmented with Redux, which allows you to work with immutable data and makes data flow unidirectional. Unidirectional binding is predictable, which facilitates the debugging process.</p>
<h3 id="heading-angular-12">Angular</h3>
<p>Angular works with bidirectional data-binding and mutable data. While the advantages of mutable and immutable data are a matter of a heated discussion, it is definitely easier to work with bidirectional data-binding rather than with the unidirectional approach. At the same time, bidirectional data-binding negatively affects the performance since Angular automatically develops a watcher for each binding.</p>
<p>The ways of data-binding in Angular:</p>
<pre><code class="lang-js">{{expression}}   Interpolation
[target]=<span class="hljs-string">"expression"</span>    Property
bind-target=<span class="hljs-string">"expression"</span>    Attribute
</code></pre>
<pre><code class="lang-js">(target)=<span class="hljs-string">"statement"</span> Event
on-target=<span class="hljs-string">"statement"</span> Event
</code></pre>
<pre><code class="lang-js">[(target)]=<span class="hljs-string">"expression"</span> Two-way
bindon-target=<span class="hljs-string">"expression"</span> Two-way
</code></pre>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/2mOdA6gBK5MqwjRRdgm5Mm/d679f1314811e0ba93ae2b106ddbf5f1/shuffle__1_.png?h=300" alt="shuffle (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-14-change-rendering">14. Change Rendering</h2>
<h3 id="heading-react-13">React</h3>
<p>React uses a virtual Document Object Model (DOM), which enables easily implementing minor data changes in one element without updating the structure of the entire tree. The framework creates an in-memory cache of data structure, computes the changes, and efficiently updates the DOM displayed in the browser. This way, the entire page seems to be rendered on each change, whereas actually, the libraries render changed subcomponents only. </p>
<p>The React team is constantly improving Fiber – a mechanism aimed at boosting the productivity of change rendering.</p>
<h3 id="heading-angular-13">Angular</h3>
<p>Angular uses a real DOM, which updates the entire tree structure even when the changes have taken place in a single element. The real DOM is considered to be slower and less effective than the virtual DOM. </p>
<p>To compensate for this disadvantage, Angular uses change detection to identify components that need to be altered. Therefore, the real DOM on Angular performs as effectively as the virtual DOM on React.</p>
<p><img src="https://images.ctfassets.net/6xhdtf1foerq/77lE2Lv97WHOpaxBVDPjfX/2b4e6f55becbd8aae05b983cb072f3c7/edit__1_.png?h=300" alt="edit (1)" width="256" height="256" loading="lazy"></p>
<h2 id="heading-15-tools">15. Tools</h2>
<h3 id="heading-react-14">React</h3>
<p>React is supported by multiple code editors. For instance, the code in React can be edited with <a target="_blank" href="https://www.sublimetext.com/">Sublime Text</a>, <a target="_blank" href="https://visualstudio.microsoft.com/">Visual Studio</a>, and <a target="_blank" href="https://atom.io/">Atom</a>. To bootstrap a project, you can use the Create React App (CLI) tool. In turn, server-side rendering is completed with the use of Next.js framework.</p>
<p>To test the entire app written in React, you would need multiple tools. For instance, <a target="_blank" href="https://github.com/airbnb/enzyme">Enzyme</a> for component testing, <a target="_blank" href="https://jestjs.io/">Jest</a> for testing JS code, React-unit for unit testing and so on. To debug the app in the development mode, you can use a browser extension React Dev Tools.</p>
<p>Another interesting tool is <a target="_blank" href="https://github.com/facebook/react-360">React 360</a>, which is a library used for creating AR and VR applications.</p>
<h3 id="heading-angular-14">Angular</h3>
<p>Similarly to React, Angular is supported by a variety of code editing tools. For example, you may work with such code editors as <a target="_blank" href="http://www.aptana.com/">Aptana</a>, <a target="_blank" href="https://www.sublimetext.com/">Sublime Text</a>, and <a target="_blank" href="https://visualstudio.microsoft.com/">Visual Studio</a>. A project can be promptly set up with <a target="_blank" href="https://cli.angular.io/">Angular CLI</a>. Server-side rendering is completed with the help of <a target="_blank" href="https://github.com/angular/universal">Angular Universal</a>.</p>
<p>Unlike React, Angular can be fully tested with a single tool. For the end-to-end testing in Angular, the platforms are <a target="_blank" href="https://jasmine.github.io/2.0/introduction.html">Jasmine</a>, <a target="_blank" href="http://www.protractortest.org/#/">Protractor</a>, and <a target="_blank" href="https://karma-runner.github.io/latest/index.html">Karma</a>. Another tool that debugs the app in the development mode is a browser extension <a target="_blank" href="https://augury.rangle.io/">Augury</a>.</p>
<h2 id="heading-to-wrap-up">To Wrap Up</h2>
<p><strong>Angular</strong> is a full-fledged mobile and web development framework. <strong>React</strong> is a framework only for UI development, which can be turned into a full-fledged solution with the help of additional libraries. </p>
<p>React seems simpler at first sight, and it takes less time to start working on a React project. However, that simplicity as the main advantage of React is neutralized because you have to learn to work with additional JavaScript frameworks and tools. </p>
<p>Angular itself is more complex and takes quite some time to master. Yet, it is a powerful tool that offers a holistic web development experience, and once you learn how to work with it, you reap the fruits. </p>
<p><strong>There is no better framework. Both are updated continuously to keep up with the competitor</strong>. For instance, while React was believed to win because of its virtual DOM, Angular equaled the score by implementing change detection. While Angular was considered to be winning because of being developed by such an authoritative company as Google, the immense devoted React community fully compensated for Google's reputation and made React similar to Angular. </p>
<p><strong>In the end, React vs Angular is all a matter of personal preference, a matter of skills and habits</strong>. As a beginner in programming, you would probably benefit more from starting with React. As an experienced developer, you just keep working with what you know better. </p>
<p>Do not forget to challenge yourself and start learning a new framework, React or Angular. As a Project Manager or a business owner outsourcing developers, you should talk to your web development team and together choose the framework that suits all of you best, whether it be Angular or React.</p>
<h2 id="heading-do-you-have-an-idea-for-either-an-angular-or-react-project">Do you have an idea for either an Angular or React project?</h2>
<p>My company KeenEthics is experienced in <a target="_blank" href="https://keenethics.com/tech-front-end-react">react development</a>, and we, also, provide outstanding <a target="_blank" href="https://keenethics.com/tech-front-end-angular">agularjs developers</a> for your projects. In case you need the following services, feel free to <a target="_blank" href="https://keenethics.com/contacts">get in touch</a><em>.</em></p>
<p>If you have enjoyed the article, you should definitely read another wonderful comparison of 2 JS frameworks: <a target="_blank" href="https://keenethics.com/blog/react-vs-svelte-how-to-build-messaging-components">React vs Svelte: How to Build Messaging Components</a>.</p>
<h2 id="heading-ps">P.S.</h2>
<p>I would like to say thank you to everyone who contributed to this article including Sergey Gornostaev and Volodya Andrushchak, full-stack software developers @ KeenEthics.</p>
<p>The original article posted on KeenEthics blog can be found here: <a target="_blank" href="https://keenethics.com/blog/angular-vs-react-what-to-choose-for-your-app">Angular vs React: Which One to Choose for Your App</a>.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to use JavaScript libraries in Angular 2+ apps ]]>
                </title>
                <description>
                    <![CDATA[ By Mohammad Kermani Do you remember when you were learning AngularJS (version 1), and tutorials kept telling you that you don’t need to add JQuery into your project?  That hasn't changed - you don’t need to add JQuery to your Angular 2+ project. But ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-use-javascript-libraries-in-angular-2-apps/</link>
                <guid isPermaLink="false">66d45f66a326133d124409f5</guid>
                
                    <category>
                        <![CDATA[ Angular ]]>
                    </category>
                
                    <category>
                        <![CDATA[ angular2 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ angular6 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 12 Jun 2019 09:57:10 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/1_FDIQCYA3BNp9Ek-tqGeQjA-1--1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Mohammad Kermani</p>
<p><em>Do you remember when you were learning AngularJS (version 1), and tutorials kept telling you that you don’t need to add JQuery into your project?</em> </p>
<p>That hasn't changed - you don’t need to add JQuery to your Angular 2+ project. But if, for any reason, you might need to use some JavaScript libraries, you need to know how to use them in Angular. So, let’s get started from zero.</p>
<p><em>I’m going to add</em> <a target="_blank" href="http://underscorejs.org/"><em>underscore.js</em></a> <em>to a project and show you how it works.</em></p>
<h3 id="heading-1-create-a-new-project-using-angular-cli">1. Create a new project using Angular CLI</h3>
<p>If you don’t already have CLI installed on your machine, <a target="_blank" href="https://cli.angular.io/">install it</a>. After installation, create a new project (if you don’t already have one).</p>
<p>ng new learning</p>
<p>Now you will have a new Angular project named “<strong>learning</strong>”.</p>
<h3 id="heading-2-install-the-package-into-your-project">2. Install the package into your project</h3>
<p>Go to the project we just made:</p>
<p>cd learning</p>
<p>Use your preferred package manager to install the library you’re going to use; I use <code>npm</code> to install <code>underscore.js</code>.</p>
<p>npm install --save underscore</p>
<h3 id="heading-3-import-the-library-into-angular-typescript">3. Import the library into Angular (TypeScript)</h3>
<p>We are writing code in TypeScript, and we should follow its rules. TypeScript needs to understand <code>underscore.js</code>.</p>
<p>As you might know, TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript has its own syntax, function and variables can have defined types. But when we are going to use an external library such as underscore, we need to declare type definitions for TypeScript.</p>
<p>In JavaScript, the type of arguments are not important and you will not get an error while you’re writing code. But TypeScript won’t let you to give an array to a function that accepts a string as input. Then here is the question: should we rewrite the <code>underscore.js</code> in TypeScript and define types there?</p>
<p>Of course not - TypeScript provides declaration files <em>(*.d.ts)</em> which define types and standardize a JavaScript file/libraries for TypeScript.</p>
<p>Some libraries include a typing file and you don’t need to install TypeScript’s type destination for them. But in case a library does not have a  <code>.d.ts</code> file, you need to install it.</p>
<p>We just need to find and import <code>underscore.js</code> type definition file. I suggest that you use <a target="_blank" href="https://microsoft.github.io/TypeSearch/">Type Search</a> to find the declaration file for the libraries you need.</p>
<p>Search for <code>underscore</code> in <a target="_blank" href="https://microsoft.github.io/TypeSearch/">Type Sceach</a> and it redirects you to<a target="_blank" href="https://www.npmjs.com/package/@types/underscore">types/underscore</a>. Install the declaration file using the following command:</p>
<p><code>npm install --save @types/underscore</code></p>
<h3 id="heading-4-import-type-declaration-into-angular-app">4. Import type declaration into Angular app</h3>
<p>Let’s say you’re going to use underscore in your <code>app.component.ts</code> file. Open the <code>app.component.ts</code> by your IDE and add the following code in the top of the file:</p>
<pre><code><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> _ <span class="hljs-keyword">from</span> <span class="hljs-string">'underscore'</span>;<span class="hljs-comment">/*** OR simply:* import 'underscore';*/</span>
</code></pre><p>The TypeScript in that component now understands <code>_</code> and it easily works as expected.</p>
<h3 id="heading-question-how-to-use-a-library-which-does-not-have-type-definition-dts-in-typescript-and-angular">Question: How to use a library which does not have type definition (*.d.ts) in TypeScript and Angular?</h3>
<p>Create it if the <code>src/typings.d.ts</code> does not exist. Otherwise open it, and add your package to it:</p>
<pre><code>declare <span class="hljs-keyword">var</span>
</code></pre><p>In your TypeScript, now you need to import it by the given name:</p>
<pre><code><span class="hljs-keyword">import</span> * <span class="hljs-keyword">as</span> yourPreferedName <span class="hljs-keyword">from</span> <span class="hljs-string">'yourLibrary'</span>;yourPreferedName.method();
</code></pre><h3 id="heading-conclusion">Conclusion</h3>
<p>To wrap up, let’s make a simple example to see a working example of <code>_</code>. Open <code>app.component.ts</code> and inside the <code>appComponent</code> class write a <code>constructor</code> which returns the last item of an array using underscore's <code>_.last()</code> function:</p>
<pre><code>...
import * <span class="hljs-keyword">as</span> _ <span class="hljs-keyword">from</span> <span class="hljs-string">'underscore'</span>;
...
export <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppComponent</span> </span>{
  <span class="hljs-keyword">constructor</span>() {
    <span class="hljs-keyword">const</span> myArray: number[] = [<span class="hljs-number">9</span>, <span class="hljs-number">1</span>, <span class="hljs-number">5</span>];
    <span class="hljs-keyword">const</span> lastItem: number = _.last(myArray); <span class="hljs-comment">//Using underscore</span>
    <span class="hljs-built_in">console</span>.log(lastItem); <span class="hljs-comment">//5</span>
  }
}
</code></pre><p>If you open your Angular app now, you will get <code>5</code> in the console, which means we could correctly add <code>underscore</code> into our project and it’s working as expected.</p>
<p>You can add any JavaScript libraries to your project just by following the same steps.</p>
<hr>
<p>You can follow <a target="_blank" href="https://medium.com/@kermani">me</a> for more articles on technology and programming.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn how to create your first Angular app in 20 minutes ]]>
                </title>
                <description>
                    <![CDATA[ By Said Hayani Angular is a JavaScript framework, created my Misko Hevery and maintained by Google. It’s an MVC (Model View Vontroller). You can visit the official page to learn more about it. Right now, the latest version of Angular is 5.2.10. There... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-how-to-create-your-first-angular-app-in-20-min-146201d9b5a7/</link>
                <guid isPermaLink="false">66d460df8812486a37369d4c</guid>
                
                    <category>
                        <![CDATA[ angular2 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Front-end Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 09 Mar 2018 18:45:43 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/0*WzYWvtV9CbhkCorg." medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Said Hayani</p>
<p>Angular is a JavaScript framework, created my Misko Hevery and maintained by Google. It’s an MVC (Model View Vontroller). You can <a target="_blank" href="https://angular.io/">visit the official page</a> to learn more about it.</p>
<p>Right now, the latest version of Angular is <strong>5.2.10.</strong> There is <a target="_blank" href="https://angularjs.org/">first generation 1.</a>x and <a target="_blank" href="https://angular.io/">second generation 2.x</a>, and the two generations are totally different in their structures and methods. Don’t worry if you feel confused about the version, because in this article we will be using the second generation 2.x</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/hq0cvYK9ku0jw7BckSTe1bQyVtDh2PVSZeMu" alt="Image" width="600" height="403" loading="lazy"></p>
<h4 id="heading-table-of-contents"><strong>Table of contents</strong></h4>
<ul>
<li>Adding an item (learn how to submit a form in Angular )</li>
<li>Removing an item (learn how to add an event in Angular)</li>
<li>Angular animation (learn how animate the components )</li>
</ul>
<h3 id="heading-prerequisites">Prerequisites:</h3>
<ul>
<li><strong>Node.js</strong></li>
</ul>
<p>Check if node.js is installed in your computer. <a target="_blank" href="https://nodejs.org/en/download/package-manager/">Learn more about installation</a>.</p>
<ul>
<li><strong>npm</strong></li>
</ul>
<p><strong>npm</strong> (node package manager) is installed with Node.js</p>
<p>Check the <strong>node.js</strong> version:</p>
<pre><code>node -v
</code></pre><p><strong>npm:</strong></p>
<pre><code>npm -v
</code></pre><p><strong>Angular-CLI</strong></p>
<p>You should have the latest version of Angular-CLI. Learn more about Angular CLI <a target="_blank" href="https://angular.io/guide/quickstart"><strong>here</strong></a><strong>,</strong> and find the instructions for installation.</p>
<p>Install Angular-cli:</p>
<pre><code>npm install -g @angular/cli
</code></pre><p>And finally, you should have:</p>
<ul>
<li>Basic knowledge of JavaScript</li>
<li>HTML and CSS fundamentals</li>
</ul>
<p>You don’t need to have any knowledge of Angular.</p>
<p>Now that we have the environment to run our Angular app, let’s get started!</p>
<h3 id="heading-creating-our-first-app">Creating our first app</h3>
<p>We will use angular-cli to create and generate our components. It will generate services, router, components, and directives.</p>
<p>To create a new Angular project with Angular-cli, just run:</p>
<pre><code>ng <span class="hljs-keyword">new</span> my-app
</code></pre><p>The project will be generated automatically. Let’s create our to-do app!</p>
<pre><code>ng <span class="hljs-keyword">new</span> todo-app
</code></pre><p>Then, open the files in your text editor. I use Sublime text, but you can choose any editor.</p>
<p>Here’s what the app structure looks like:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ptdxoFrfKYkg1O7Kjzfm2vfQxlsrM5ggfSoR" alt="Image" width="200" height="637" loading="lazy"></p>
<p>Don’t worry if you are confused about the files. All of our work will be in the <strong>app</strong> folder. It contains five files:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/icEs5nlfczvJiEgX7j4EUCcevZFnKCOXocqD" alt="Image" width="234" height="89" loading="lazy"></p>
<blockquote>
<p>Note: Angular 2 uses <strong>TypeScript</strong>, in which files end with “<strong>.ts”</strong>extension.</p>
</blockquote>
<p>To make a nice interface for our app, we will use the <a target="_blank" href="http://getbootstrap.com/">Bootstrap 4</a> Framework.</p>
<p>Include bootstrap <strong>cdn</strong> in <strong>index.html</strong>:</p>
<pre><code>&lt;link rel=<span class="hljs-string">"stylesheet"</span> href=<span class="hljs-string">"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"</span> integrity=<span class="hljs-string">"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"</span> crossorigin=<span class="hljs-string">"anonymous"</span>&gt;
</code></pre><p>Run the app in your terminal:</p>
<pre><code>ng serve
</code></pre><p>The app will run in <a target="_blank" href="http://localhost:4200/">http://localhost:4200/</a></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/gwml-v8qHlrNVra-yfJOZH1Kdqx2oRnwrWYF" alt="Image" width="366" height="717" loading="lazy"></p>
<p>All is well ?!</p>
<p>Now let’s do some HTML structuring. We will use Bootstrap classes to create a simple form.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ioyTYMvqC7Izykcin7U1OAEE9pIO7Tn9CWGB" alt="Image" width="471" height="398" loading="lazy"></p>
<p><strong>app.component.html</strong>:</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"container"</span>&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-center text-primary"</span>&gt;</span>Todo App<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-group-prepend"</span>&gt;</span>       <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Add Todo"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"todo"</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-group-text"</span>&gt;</span>Add<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>   <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre><p>In <strong>app.component.css</strong>:</p>
<pre><code>body{ <span class="hljs-attr">padding</span>: <span class="hljs-number">0</span>; margin: <span class="hljs-number">0</span>;
</code></pre><pre><code>}form{ max-width: <span class="hljs-number">25</span>em; margin: <span class="hljs-number">1</span>em auto;}
</code></pre><p>To capture the input value in Angular 2, we can use the <strong>ngModel</strong> directive. You can insert a variable as an attribute inside the input element.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/9x5e9yWah1OqD5OpVTfMAxz5fzEjn1e3jLjD" alt="Image" width="341" height="224" loading="lazy"></p>
<pre><code>&lt;input type=<span class="hljs-string">"text"</span> #todo <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"form-control"</span> placeholder=<span class="hljs-string">"Add Todo"</span> name=<span class="hljs-string">"todo"</span> ngModel&gt;
</code></pre><p>To create a variable as an attribute, use <strong>#</strong> followed by the variable’s name.</p>
<pre><code>&lt;input #myVariable type=<span class="hljs-string">"text"</span> name=<span class="hljs-string">"text"</span> ngModel&gt;
</code></pre><pre><code><span class="hljs-comment">// get the value of the Variable&lt;p&gt;{{myVariable.value}}&lt;/p&gt;</span>
</code></pre><p>Now get the “todo” variable value:</p>
<pre><code>&lt;p&gt;{{todo.value}}&lt;/p&gt;
</code></pre><p>All is well ?!</p>
<p>Now we have to store the value captured from the input. We can create an empty array in <strong>app.component.ts</strong> inside the AppComponent class:</p>
<pre><code><span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppComponent</span> </span>{  todoArray=[] }
</code></pre><p>Then we have to add a click event to our button that pushes the value captured into “<strong>todoArray</strong>”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/YiBkAM7A8VteVRe3Ok0KBWaVscJ1QRk9ciL9" alt="Image" width="508" height="309" loading="lazy"></p>
<p><strong>app.component.html</strong>:</p>
<pre><code>&lt;span <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"input-group-text"</span> (click)=<span class="hljs-string">"addTodo(todo.value)"</span>&gt;Add&lt;/span&gt;
</code></pre><p>In <strong>app.component.ts</strong>:</p>
<pre><code><span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppComponent</span> </span>{ todoArray=[]
</code></pre><pre><code>addTodo(value){    <span class="hljs-built_in">this</span>.todoArray.push(value)    <span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>.todos)  } }
</code></pre><blockquote>
<p>Use console.log(this.todoArray) to see Array value</p>
</blockquote>
<h4 id="heading-fetch-data-from-todoarray">Fetch data from “todoArray”</h4>
<p>Now we have to fetch data stored in “todosArray.” We will use the <em>[<em>*ngFor directive</em></em>](https://angular.io/guide/structural-directives) to loop through the array and extract the data.</p>
<p>app.component.html:</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"data"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"list-instyled"</span>&gt;</span>   <span class="hljs-tag">&lt;<span class="hljs-name">li</span> *<span class="hljs-attr">ngFor</span>=<span class="hljs-string">"let todo of todoArray"</span>&gt;</span>{{todo}}<span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span></span>  &lt;/div&gt;
</code></pre><p>After fetching data:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/IdbbBDKFN29rGZisR0ygAKwKdTUPexZ7-hYD" alt="Image" width="526" height="303" loading="lazy"></p>
<p>The data will now be fetched automatically when we click the add button.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Yyeff6WTcxF-b39yi6zMtpe9UWzjZ9NhZBWs" alt="Image" width="600" height="410" loading="lazy"></p>
<h4 id="heading-styling-the-app">Styling the app</h4>
<p>I like to use <a target="_blank" href="https://fonts.google.com">Google-fonts</a> and <a target="_blank" href="https://material.io/icons/">Material-icons</a>, which are free to use.</p>
<p>Include Google fonts inside <strong>app.component.css</strong>:</p>
<pre><code><span class="hljs-comment">/*Google fonts*/</span>@<span class="hljs-keyword">import</span> url(<span class="hljs-string">'https://fonts.googleapis.com/css?family=Raleway'</span>);
</code></pre><p>And Material-icons inside <strong>index.html</strong>:</p>
<pre><code>&lt;link href=<span class="hljs-string">"https://fonts.googleapis.com/icon?family=Material+Icons"</span> rel=<span class="hljs-string">"stylesheet"</span>&gt;
</code></pre><p>After adding some styling to our app, it will look like this:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Bb8mPSgYnJuwIEHA3-cRc8yR0q1YId96ppmi" alt="Image" width="678" height="624" loading="lazy"></p>
<p>To use Material icons:</p>
<pre><code>&lt;i <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"material-icons&gt;iconName&lt;/i&gt;</span>
</code></pre><p>Add “delete” and “add” icons in <strong>app.component.html</strong>:</p>
<pre><code><span class="hljs-comment">// put add icon inside "input-group-text" div</span>
</code></pre><pre><code>&lt;span <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"input-group-text"</span> (click)=<span class="hljs-string">"addTodo(todo.value)"</span>&gt;<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"material-icons"</span>&gt;</span>add<span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span></span>&lt;/span&gt;
</code></pre><pre><code><span class="hljs-comment">// and delete icon inside list item &lt;li *ngFor="let todo of todoArray"&gt;{{todo}}&lt;i class="material-icons"&gt;delete&lt;/i&gt;&lt;/li&gt;</span>
</code></pre><p>For styles in <strong>app.component.css</strong>:</p>
<pre><code><span class="hljs-comment">/*Google fonts*/</span>@<span class="hljs-keyword">import</span> url(<span class="hljs-string">'https://fonts.googleapis.com/css?family=Raleway'</span>);
</code></pre><pre><code>body{ <span class="hljs-attr">padding</span>: <span class="hljs-number">0</span>; margin: <span class="hljs-number">0</span>;
</code></pre><pre><code>}form{ max-width: <span class="hljs-number">30</span>em; margin: <span class="hljs-number">4</span>em auto; position: relative; background: #f4f4f4; padding: <span class="hljs-number">2</span>em <span class="hljs-number">3</span>em;}form h1{    font-family: <span class="hljs-string">"Raleway"</span>;    color:#F97300; }form input[type=text]::placeholder{   font-family: <span class="hljs-string">"Raleway"</span>;   color:#<span class="hljs-number">666</span>; }form .data{    margin-top: <span class="hljs-number">1</span>em;}form .data li{ <span class="hljs-attr">background</span>: #fff; border-left: <span class="hljs-number">4</span>px solid #F97300; padding: <span class="hljs-number">1</span>em; margin: <span class="hljs-number">1</span>em auto; color: #<span class="hljs-number">666</span>; font-family: <span class="hljs-string">"Raleway"</span>;}form .data li i{    <span class="hljs-attr">float</span>: right;    color: #<span class="hljs-number">888</span>;    cursor: pointer;}form .input-group-text{    <span class="hljs-attr">background</span>: #F97300;    border-radius: <span class="hljs-number">50</span>%;    width: <span class="hljs-number">5</span>em;    height: <span class="hljs-number">5</span>em;    padding: <span class="hljs-number">1</span>em <span class="hljs-number">23</span>px;    color: #fff;    position: absolute;    right: <span class="hljs-number">13</span>px;    top: <span class="hljs-number">68</span>px;    cursor: pointer;}form .input-group-text i{    font-size: <span class="hljs-number">2</span>em;}form .form-control{ <span class="hljs-attr">height</span>: <span class="hljs-number">3</span>em;    font-family: <span class="hljs-string">"Raleway"</span>;}form .form-control:focus{ box-shadow: <span class="hljs-number">0</span>;}
</code></pre><p>Our app is almost done, but we need to add some features. A delete functionality should let users click a delete icon and delete an item. It would also be great to have the option to enter a new item with the return key, instead of clicking the add button.</p>
<p><strong>Deleting items</strong></p>
<p>To add the delete functionality, we will use the “splice” array method and a for loop. We will loop through “todoarray” and extract the item we want to delete.</p>
<p>Add a (click) event to delete icon and give it “todo” as parameter :</p>
<pre><code>&lt;li *ngFor=<span class="hljs-string">"let todo of todoArray"</span>&gt;{{todo}} &lt;i (click)=<span class="hljs-string">"deleteItem(todo)"</span> <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"material-icons"</span>&gt;<span class="hljs-keyword">delete</span>&lt;<span class="hljs-regexp">/i&gt;&lt;/</span>li&gt;
</code></pre><p>In <strong>app.component.ts</strong>:</p>
<pre><code><span class="hljs-comment">/*delete item*/</span>  deleteItem(){   <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"delete item"</span>)  }
</code></pre><p>When you click delete, this should show up in the console:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/nWS2NAJXn4iaQL6vqGwiaUBVSY64XUxerN4w" alt="Image" width="488" height="186" loading="lazy"></p>
<p>Now we have to loop through “todoArray” and splice the item we clicked.</p>
<p>In <strong>app.component.ts</strong>:</p>
<pre><code><span class="hljs-comment">/*delete item*/</span>  deleteItem(todo){   <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span> ;i&lt;= <span class="hljs-built_in">this</span>.todoArray.length ;i++){    <span class="hljs-keyword">if</span>(todo== <span class="hljs-built_in">this</span>.todoArray[i]){     <span class="hljs-built_in">this</span>.todoArray.splice(i,<span class="hljs-number">1</span>)    }   }  }
</code></pre><p>The result:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/bJVYplDX6DgQ39ZaN3eYhBcenCi86fqxbov0" alt="Image" width="600" height="594" loading="lazy"></p>
<p>Awesome ?!!</p>
<h4 id="heading-entering-to-add-items"><strong>Entering to add items</strong></h4>
<p>We can add a submit event to the form:</p>
<pre><code>(ngSubmit)=<span class="hljs-string">"TodoSubmit()"</span>
</code></pre><p>We need to add the variable “#todoForm” to the form and give it “ngForm” as a value. In this case, we just have one field so we will just get a single value. If we have multiple fields, the submit event will return the values of all the fields in the form.</p>
<p><strong>app.component.html</strong></p>
<pre><code>&lt;form #todoForm= <span class="hljs-string">"ngForm"</span> (ngSubmit)=<span class="hljs-string">"todoSubmit(todoForm.value)"</span>&gt;&lt;/form&gt;
</code></pre><p>in <strong>app.component.ts</strong></p>
<pre><code><span class="hljs-comment">// submit Form  todoSubmit(value:any){ console.log(value)  }</span>
</code></pre><p>Check the console. It will return an object of values:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/HBlkb6jnVHcHyTGJ1lEff1dcy2ok-T7glk42" alt="Image" width="311" height="204" loading="lazy"></p>
<p>So now we have to push the returned value to “todoArray”:</p>
<pre><code><span class="hljs-comment">// submit Form  todoSubmit(value:any){     if(value!==""){    this.todoArray.push(value.todo)     //this.todoForm.reset()    }else{      alert('Field required **')    }      }</span>
</code></pre><p>Here we are ?. The value is inserted without needing to click the add button, just by clicking “enter”:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/OWpohuUVC7SjOCGfavFkTnoU2D1sR1CgQj8r" alt="Image" width="600" height="594" loading="lazy"></p>
<p>One more thing. To reset the the form after submitting, add the “resetForm()” build-in method to submit the event.</p>
<pre><code>&lt;form #todoForm= <span class="hljs-string">"ngForm"</span> (ngSubmit)=<span class="hljs-string">"todoSubmit(todoForm.value); todoForm.resetForm()"</span> &gt;&lt;/form&gt;
</code></pre><p>The form will reset after each submit now:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/0w5t7IIt4Wj4KBolctdZBNFQrwr4ucCLL6or" alt="Image" width="600" height="594" loading="lazy"></p>
<h4 id="heading-adding-animations">Adding animations</h4>
<p>I like to add a little touch of animations. To add animation, import the animations components in your <strong>app.component.ts</strong>:</p>
<pre><code><span class="hljs-keyword">import</span> { Component,trigger,animate,style,transition,keyframes } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
</code></pre><p>Then add the animations property to “@component” decorator:</p>
<pre><code>@Component({  <span class="hljs-attr">selector</span>: <span class="hljs-string">'app-root'</span>,  <span class="hljs-attr">templateUrl</span>: <span class="hljs-string">'./app.component.html'</span>,  <span class="hljs-attr">styleUrls</span>: [<span class="hljs-string">'./app.component.css'</span>],  <span class="hljs-attr">animations</span>:[   trigger(<span class="hljs-string">"moveInLeft"</span>,[      transition(<span class="hljs-string">"void=&gt; *"</span>,[style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(300px)"</span>}),        animate(<span class="hljs-number">200</span>,keyframes([         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(300px)"</span>}),         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(0)"</span>})           ]))]),
</code></pre><pre><code>transition(<span class="hljs-string">"*=&gt;void"</span>,[style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(0px)"</span>}),        animate(<span class="hljs-number">100</span>,keyframes([         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(0px)"</span>}),         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(300px)"</span>})           ]))])             ])
</code></pre><pre><code>]})
</code></pre><p>Now the items have a nice effect when they’re entered and deleted.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/4ugLJyeDD6oGnKg6jc47KqRc692d4H376pqr" alt="Image" width="600" height="334" loading="lazy"></p>
<h3 id="heading-all-the-code">All the code</h3>
<p><strong>app.component.ts</strong></p>
<pre><code><span class="hljs-keyword">import</span> { Component,trigger,animate,style,transition,keyframes } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;
</code></pre><pre><code>@Component({  <span class="hljs-attr">selector</span>: <span class="hljs-string">'app-root'</span>,  <span class="hljs-attr">templateUrl</span>: <span class="hljs-string">'./app.component.html'</span>,  <span class="hljs-attr">styleUrls</span>: [<span class="hljs-string">'./app.component.css'</span>],  <span class="hljs-attr">animations</span>:[   trigger(<span class="hljs-string">"moveInLeft"</span>,[      transition(<span class="hljs-string">"void=&gt; *"</span>,[style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(300px)"</span>}),        animate(<span class="hljs-number">200</span>,keyframes([         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(300px)"</span>}),         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(0)"</span>})           ]))]),
</code></pre><pre><code>transition(<span class="hljs-string">"*=&gt;void"</span>,[style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(0px)"</span>}),        animate(<span class="hljs-number">100</span>,keyframes([         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(0px)"</span>}),         style({<span class="hljs-attr">transform</span>:<span class="hljs-string">"translateX(300px)"</span>})           ]))])             ])
</code></pre><pre><code>]})<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppComponent</span> </span>{  todoArray=[];  todo;  <span class="hljs-comment">//todoForm: new FormGroup()</span>
</code></pre><pre><code>addTodo(value){    <span class="hljs-keyword">if</span>(value!==<span class="hljs-string">""</span>){     <span class="hljs-built_in">this</span>.todoArray.push(value)    <span class="hljs-comment">//console.log(this.todos)   }else{    alert('Field required **')  }      }</span>
</code></pre><pre><code><span class="hljs-comment">/*delete item*/</span>  deleteItem(todo){   <span class="hljs-keyword">for</span>(<span class="hljs-keyword">let</span> i=<span class="hljs-number">0</span> ;i&lt;= <span class="hljs-built_in">this</span>.todoArray.length ;i++){    <span class="hljs-keyword">if</span>(todo== <span class="hljs-built_in">this</span>.todoArray[i]){     <span class="hljs-built_in">this</span>.todoArray.splice(i,<span class="hljs-number">1</span>)    }   }  }
</code></pre><pre><code><span class="hljs-comment">// submit Form  todoSubmit(value:any){     if(value!==""){    this.todoArray.push(value.todo)     //this.todoForm.reset()    }else{      alert('Field required **')    }      } }</span>
</code></pre><p><strong>app.component.html</strong></p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">"container"</span>&gt; <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">form</span> #<span class="hljs-attr">todoForm</span>= <span class="hljs-string">"ngForm"</span>(<span class="hljs-attr">submit</span>)=<span class="hljs-string">"todoSubmit(todoForm.value); todoForm.resetForm()"</span> &gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"form-group"</span>&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"text-center "</span>&gt;</span>Todo App<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>   <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-group-prepend"</span>&gt;</span>       <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span> #<span class="hljs-attr">todo</span>  <span class="hljs-attr">class</span>=<span class="hljs-string">"form-control"</span> <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Add Todo"</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"todo"</span> <span class="hljs-attr">ngModel</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"input-group-text"</span> (<span class="hljs-attr">click</span>)=<span class="hljs-string">"addTodo(todo.value)"</span>&gt;</span>    <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"material-icons"</span>&gt;</span>add<span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>   <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"data"</span>&gt;</span>  <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"list-unstyled"</span>&gt;</span>   <span class="hljs-tag">&lt;<span class="hljs-name">li</span> [@<span class="hljs-attr">moveInLeft</span>]  *<span class="hljs-attr">ngFor</span>=<span class="hljs-string">"let todo of todoArray"</span>&gt;</span>{{todo}} <span class="hljs-tag">&lt;<span class="hljs-name">i</span> (<span class="hljs-attr">click</span>)=<span class="hljs-string">"deleteItem(todo)"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"material-icons"</span>&gt;</span>delete<span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span> <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre><p><strong>app.component.css</strong></p>
<pre><code><span class="hljs-comment">/*Google fonts*/</span>@<span class="hljs-keyword">import</span> url(<span class="hljs-string">'https://fonts.googleapis.com/css?family=Raleway'</span>);
</code></pre><pre><code>body{ <span class="hljs-attr">padding</span>: <span class="hljs-number">0</span>; margin: <span class="hljs-number">0</span>;
</code></pre><pre><code>}form{ max-width: <span class="hljs-number">30</span>em; margin: <span class="hljs-number">4</span>em auto; position: relative;    background: #f4f4f4;    padding: <span class="hljs-number">2</span>em <span class="hljs-number">3</span>em;    overflow: hidden;}form h1{    font-family: <span class="hljs-string">"Raleway"</span>;    color:#F97300; }form input[type=text]::placeholder{   font-family: <span class="hljs-string">"Raleway"</span>;   color:#<span class="hljs-number">666</span>; }form .data{    margin-top: <span class="hljs-number">1</span>em;}form .data li{ <span class="hljs-attr">background</span>: #fff; border-left: <span class="hljs-number">4</span>px solid #F97300; padding: <span class="hljs-number">1</span>em; margin: <span class="hljs-number">1</span>em auto; color: #<span class="hljs-number">666</span>; font-family: <span class="hljs-string">"Raleway"</span>;}form .data li i{    <span class="hljs-attr">float</span>: right;    color: #<span class="hljs-number">888</span>;    cursor: pointer;}form .input-group-text{    <span class="hljs-attr">background</span>: #F97300;    border-radius: <span class="hljs-number">50</span>%;    width: <span class="hljs-number">5</span>em;    height: <span class="hljs-number">5</span>em;    padding: <span class="hljs-number">1</span>em <span class="hljs-number">23</span>px;    color: #fff;    position: absolute;    right: <span class="hljs-number">13</span>px;    top: <span class="hljs-number">68</span>px;    cursor: pointer;}form .input-group-text i{    font-size: <span class="hljs-number">2</span>em;}form .form-control{ <span class="hljs-attr">height</span>: <span class="hljs-number">3</span>em;    font-family: <span class="hljs-string">"Raleway"</span>;}form .form-control:focus{ box-shadow: <span class="hljs-number">0</span>;}
</code></pre><p>We are done ?. You can find the files and code on <a target="_blank" href="https://github.com/hayanisaid/Todo-app-in-Angular">Github.</a></p>
<h4 id="heading-see-the-demohttpsstackblitzcomedittodo-app-in-angularfileindexhtml"><a target="_blank" href="https://stackblitz.com/edit/todo-app-in-angular?file=index.html">See the Demo</a></h4>
<h3 id="heading-conclusion">Conclusion</h3>
<p>Angular is easier than you think. Angular is one of the best JavaScript libraries, and it has great support and a nice community. It also has tools that make working with Angular fast and easy, like Angular-cli.</p>
<p>Subscribe to this <a target="_blank" href="http://eepurl.com/dk9OJL">mail-list</a> to learn more about Angular.</p>
<p><a target="_blank" href="https://twitter.com/hayanisaid1995"><strong>SaidHayani@ (@hayanisaid1995) | Twitter</strong></a><br><a target="_blank" href="https://twitter.com/hayanisaid1995">_The latest Tweets from SaidHayani@ (@hayanisaid1995). #Web_Developer /#Frontend / #Back_end(#PHP &amp;…_twitter.com</a></p>
<p>Here are some of the best online courses to learn Angular for free:</p>
<p><strong>Angular 1.x</strong></p>
<ul>
<li>S<a target="_blank" href="https://www.codeschool.com/courses/shaping-up-with-angularjs">haping with Angular</a></li>
<li><a target="_blank" href="http://www.learn-angular.org/">Learn Angular</a></li>
</ul>
<p><strong>Angular 2.x</strong> <em>(recommended)</em></p>
<ul>
<li><a target="_blank" href="https://coursetro.com/courses/8/Learn-Angular-2-Development-with-our-Free-Course">learn Angular2 (coursetro</a>)</li>
<li><a target="_blank" href="https://www.youtube.com/playlist?list=PLC3y8-rFHvwg5gEu2KF4sbGvpUqMRSBSW">YouTube playlist</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Angular’s Backyard: The Resolving of Components Dependencies ]]>
                </title>
                <description>
                    <![CDATA[ By Dor Moshe This article originally appeared on dormoshe.io Many of us use the Hierarchical Dependency Injection mechanism of Angular. We use it through a service or a component to resolve another service or provider. But, do we know what Angular do... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/angulars-backyard-the-resolving-of-component-dependencies-2015b40e5bd1/</link>
                <guid isPermaLink="false">66c344caf9d371e3aae26829</guid>
                
                    <category>
                        <![CDATA[ Angular ]]>
                    </category>
                
                    <category>
                        <![CDATA[ angular2 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Front-end Development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 28 May 2017 15:13:46 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*xym6BYUMOQmtTv-Pmbs4mQ.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Dor Moshe</p>
<p><strong><em>This</em> article</strong> <strong><em>originally appeared on <a target="_blank" href="https://dormoshe.io/articles/angulars-backyard-the-resolving-of-components-dependencies-10">dormoshe.io</a></em></strong></p>
<p>Many of us use the Hierarchical Dependency Injection mechanism of Angular. We use it through a service or a component to resolve another service or provider. But, do we know what Angular does in order to resolve the dependencies? Probably not, because Angular takes care of what we need to use it as a black box.</p>
<p>In this article, we’ll open the black box and explore the code of the component dependencies resolution mechanism.</p>
<h3 id="heading-back-to-the-basics">Back to the basics</h3>
<p><a target="_blank" href="https://blog.thoughtram.io/angular/2015/05/18/dependency-injection-in-angular-2.html">Dependency Injection</a> (DI) is a powerful pattern for managing code dependencies. Angular’s DI system <strong>creates and delivers dependent services</strong> “just-in-time”. Angular has its own DI framework, and we can’t build an Angular application without it.</p>
<p>The Angular DI system is actually a <strong>Hierarchical</strong> system. This system supports nested injectors in parallel with the component tree. An injector creates dependencies using providers. We can reconfigure the injectors at any level of that component tree. Behind the scenes, each component sets up its <strong>own injector</strong> with zero, one, or more providers defined for that component itself.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*MFEIRh2SxIjlubhqwbhVow.png" alt="Image" width="600" height="248" loading="lazy">
<em>A mini Angular injectors tree</em></p>
<h3 id="heading-resolution-order">Resolution Order</h3>
<p>The hierarchical DI has an order to the resolution of the dependencies. When a component requests a dependency, if it exists in the <code>@Component.providers</code> array (the component injector), then this dependency will be supplied.</p>
<p>Elsewhere, Angular continues to the parent component injector and checks again and again. If Angular doesn’t find an ancestor, it will supply this dependency via the application main injector. This is the core concept of the hierarchical DI mechanism.</p>
<h3 id="heading-lets-see-the-code">Let’s see the code</h3>
<p>When Angular instantiates a component, it calls the <code>resolveDep</code> function. This function's signature contains the component view container, the element, the dependency definition and some more arguments. We will focus on the component view and the dependency object. The dependency object contains only one dependency of the component.</p>
<p>Here is the <code>resolveDep</code> function skeleton from the Angular GitHub repository:</p>
<p>The function skeleton contains the main concepts of the resolution, without the edge cases. The full code can be found <a target="_blank" href="https://github.com/angular/angular/blob/master/packages/core/src/view/provider.ts#L343">here</a>. In the next parts, we will explore the function skeleton.</p>
<h4 id="heading-pausa">Pausa</h4>
<p>The Exclamation mark is a new feature of Typescript 2.0. The <code>!</code> post-fix expression operator may be used to assert that its operand is non-null and non-undefined in contexts where the type checker is unable to conclude that fact. Angular uses this feature frequently, so we should not be afraid.</p>
<h4 id="heading-part-1-preparation">Part 1 — Preparation</h4>
<p>The <code>const startView = view;</code> code saves the original view (the view container of the component) in a variable because the view variable will change soon.</p>
<p>The <code>const tokenKey = depDef.tokenKey;</code> code fetches the <strong>tokenKey</strong> or the dependency key, for example, <strong>HeroService_4</strong>. This key builds by the dependency name and a generated number to handle the dependency uniquely.</p>
<h4 id="heading-part-2-source-component-and-ancestors-search">Part 2 —Source component and Ancestors search</h4>
<p>The <strong>while</strong> loop implements the stages of checking the source <code>@Component.providers</code> and the ancestor components.<br> According to the dependency token key, the source component providers will be checked in lines 1–3:</p>
<p>If the provider exists on line 4, then the source component satisfies the dependency. So, if the dependency was instantiated in the past on line 6, the instance will return by the <code>resolveDep</code> function at line 10. If this is the first time that the component or its children ask for the dependency it will be created at line 7 and will return by the <code>resolveDep</code> function at line 10.</p>
<p>If the dependency is not found in the <code>view</code> component injector, the<br><code>elDef = viewParentEl(view) !;</code> and <code>view = view.parent !;</code> will be called to advance the variable to the parent element. The <code>while</code> loop will continue running until the dependency is found in the ancestor injector. If the dependency is still not found after checking all ancestors, the <code>while</code> loop will end and the <strong>third part</strong> will come into action.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*V2ffKO6UpnymY99JXBSCEw.jpeg" alt="Image" width="600" height="356" loading="lazy"></p>
<h4 id="heading-part-3-root-injector">Part 3 — Root injector</h4>
<p>If come to this part, the dependency can’t be satisfied by any of the component ancestors injectors. Then the <code>startView</code> or the source component will be checked at line 1:</p>
<p>If the source component or one of its ancestor components was loaded by the Router Outlet (the router component), the <strong>root</strong> injector is the <strong>Outlet Injector</strong>. This injector supplies some dependencies like the <strong>Router</strong> service. Otherwise, the root injector is the bootstrap component’s injector.</p>
<p>If the dependency is found at line 3, then the value will be returned by the <code>resolveDep</code> function. In the other case, part 4 will come into action.</p>
<h4 id="heading-part-4-application-module-injector">Part 4 — Application module injector</h4>
<p>When we come to this part, it means that the dependency can’t be satisfied by part 2 and part 3. This is the last chance to satisfy the dependency. This part’s code tries to get the dependency from the application module injector or the root module. This module contains the application-wide dependencies:<br><code>return startView.root.ngModule.injector.get(depDef.token,notFoundValue);</code></p>
<p>This part finishes the <code>resolveDep</code> flow. If the dependency is not found, then Angular can’t satisfy this dependency and it should throw an exception.</p>
<h3 id="heading-conclusion">Conclusion</h3>
<p>The Hierarchical DI is a core feature that Angular leans on a lot. Sometimes, the resolution process looks complicated and long. It’s very convenient to leave Angular to manage this flow and enjoy the ease of use. Now, after we hiked in the backyard of the component dependency resolution, we know what to expect when we use it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*cA1Y2VmIvRnUJUvjUPNZ2A.png" alt="Image" width="200" height="165" loading="lazy"></p>
<p><strong><em>You can follow me on <a target="_blank" href="https://www.dormoshe.io">dormoshe.io</a> or <a target="_blank" href="https://twitter.com/DorMoshe">Twitter</a> to read more about Angular, JavaScript and web development.</em></strong></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How Google builds web frameworks ]]>
                </title>
                <description>
                    <![CDATA[ By Filip Hracek It’s public knowledge that Google uses a single repository to share code — all 2 billion lines of it — and that it uses the trunk-based development paradigm. _This is easily one of the largest single code repositories in the world. [... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-google-builds-a-web-framework-5eeddd691dea/</link>
                <guid isPermaLink="false">66c34d2893db2451bd441481</guid>
                
                    <category>
                        <![CDATA[ angular2 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Dart ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Google ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software development ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 10 Feb 2017 09:44:29 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*QDS-kCgeF8ZJg_JSEwwIeA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Filip Hracek</p>
<p>It’s <a target="_blank" href="http://cacm.acm.org/magazines/2016/7/204032-why-google-stores-billions-of-lines-of-code-in-a-single-repository/fulltext">public knowledge</a> that Google uses a single repository to share code — all 2 billion lines of it — and that it uses the trunk-based development paradigm.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/euiRGyI4xZdUqp4RgiYsctfD2fdCo02b28HI" alt="Image" width="370" height="235" loading="lazy">
_This is easily one of the largest single code repositories in the world. [Source](http://cacm.acm.org/magazines/2016/7/204032-why-google-stores-billions-of-lines-of-code-in-a-single-repository/fulltext" rel="noopener" target="<em>blank" title=").</em></p>
<p>For many developers outside the company, this is surprising and counterintuitive, but it works really well. (The article linked above gives good examples, so I won’t repeat them here.)</p>
<blockquote>
<p>Google’s codebase is shared by more than 25,000 Google software developers from dozens of offices in countries around the world. On a typical workday, they commit 16,000 changes to the codebase. (<a target="_blank" href="http://cacm.acm.org/magazines/2016/7/204032-why-google-stores-billions-of-lines-of-code-in-a-single-repository/fulltext">source</a>)</p>
</blockquote>
<p>This article is about the specifics of building an open source web framework (<a target="_blank" href="https://webdev.dartlang.org/angular">AngularDart</a>) in this context.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/KnEFivyJP4WX7220Pp-QJL9n5Gj10o4F76BR" alt="Image" width="766" height="449" loading="lazy">
_‘Human users’ means software engineers committing code at Google. (As opposed to source generation tools.) [Source](http://cacm.acm.org/magazines/2016/7/204032-why-google-stores-billions-of-lines-of-code-in-a-single-repository/fulltext" rel="noopener" target="<em>blank" title=").</em></p>
<h3 id="heading-only-one-version">Only one version</h3>
<p>When you employ trunk-based development in a single huge repo, you have only one version of everything. That’s kind of obvious. It’s still good to point it out here, though, because it means that — at Google — you can’t have app FooBar that’s using AngularDart 2.2.1 and another app BarFoo that’s on 2.3.0. Both apps must be on the same version — the latest one.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/J-xXNDvHs6JetEFL8n2kbDIS-fq-hbjKQcxt" alt="Image" width="728" height="218" loading="lazy">
_Illustrative image taken from [trunkbaseddevelopment.com](https://trunkbaseddevelopment.com/" rel="noopener" target="<em>blank" title=").</em></p>
<p>That’s why Googlers sometimes say that all software at Google lives on the bleeding edge.</p>
<p>If your entire soul screams ‘dangerous!’ right now, that’s understandable. Depending on the trunk (‘master’ in git terminology) of a library with your production code sure sounds dangerous. But there’s a plot twist ahead.</p>
<h3 id="heading-74-thousand-tests-per-commit">74 thousand tests per commit</h3>
<p>AngularDart defines 1601 tests (<a target="_blank" href="https://github.com/dart-lang/angular2/tree/master/test">here</a>). But when you’re committing a change to AngularDart code in the Google repository, it also runs tests for <em>everyone at Google who depends on the framework</em>. At the moment, that’s about 74 thousand tests (depending on how big your change is — a heuristic skips tests that the system knows you’re not affecting).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/okJEb5P2KBDDDHfjucfSs6ZzwoypOXTuNtiY" alt="Image" width="600" height="371" loading="lazy"></p>
<p>It’s good to have more tests.</p>
<p>I just made a change that only manifests itself 5% of the time, simulating something like a race condition in the change detection reinsertion verification algorithm (I added <code>&amp;&amp; random.nextDouble() &gt;</code> .05 <a target="_blank" href="https://github.com/dart-lang/angular2/blob/v2.1.0/lib/src/core/change_detection/differs/default_iterable_differ.dart#L386">to this if statem</a>ent). It did not manifest in any of the 1601 tests when I ran them (once). But it did break a bunch of client tests.</p>
<p>The real value here, though, is that those are tests of <em>actual apps</em>. Not only are they numerous, they’re also reflecting how the framework is used by developers (not just the framework authors). This is significant: framework owners don’t always correctly estimate how their framework is being used.</p>
<p>It also helps that those apps are in production, and billions of dollars flow through them each month. There’s a big difference between demo apps that a framework author puts together in his spare time, and real production apps with tens or hundreds of person-years invested in them. If the web is to be relevant in the future, we need to better support development of the latter.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/D1mbfuT6MEY47oVUPSqBrFm68kfYjduUsa58" alt="Image" width="800" height="328" loading="lazy"></p>
<p>So what happens if the framework breaks some of the apps that are built on it?</p>
<h3 id="heading-you-break-it-you-fix-it">You break it, you fix it</h3>
<p>When AngularDart authors want to introduce a breaking change, <em>they have to go and fix it for their users</em>. Since everything at Google lives in a single repo, it’s trivial to find out whom they’re breaking, and they can start fixing right away.</p>
<p>Any breaking change to AngularDart also includes all the fixes to that change in all the Google apps that depend on it. So the breakage and the fix go into the repo simultaneously and — of course — after proper code review by all affected parties.</p>
<p>Let’s give a concrete example. When someone from the AngularDart team makes a change that affects code in the AdWords app, they go to that app’s source code and fix it. They can run AdWords’ existing tests in the process, and they can add new ones. Then, they put all of that into their change list and ask for review. Since their change list touches code in both the AngularDart repo and the AdWords repo, the system automatically requires code review approval from both of those teams. Only then can the change be submitted.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/mWtgJIIPLEqXbQoE7jEv13OprQl5snHMFmJh" alt="Image" width="619" height="458" loading="lazy"></p>
<p>This has the obvious effect of preventing framework development in a vacuum. AngularDart framework developers have access to millions of lines of code that are built with their platform, and they regularly touch that code themselves. They don’t need to assume how their framework is used. (The obvious caveat is that they only see the Google code and not the code of all the Workivas, Wrikes and StableKernels of the world that also use AngularDart.)</p>
<p>Having to upgrade your users’ code also slows development down. Not as much as you may think (look at AngularDart’s progress since October), but it still slows things down. That’s both good and bad, depending on what you want from a framework. We’ll get back to that.</p>
<p>Anyway. The next time someone at Google <a target="_blank" href="https://webdev.dartlang.org/angular/version">says</a> that an alpha version of some library is stable and in production, now you know why.</p>
<h3 id="heading-large-scale-changes">Large scale changes</h3>
<p>What if AngularDart needs to make a major breaking change (say, going from 2.x to 3.0) and that change breaks 74 thousand tests? Will the team go and fix all of them? Will they make changes to <em>thousands</em> of source files, most of which they haven’t authored?</p>
<p>Yes.</p>
<p>One of the cool things about having a <a target="_blank" href="https://www.dartlang.org/guides/language/sound-dart">sound type system</a> is that your tooling can be much more useful. In sound Dart, tools can be sure that a variable is of a certain type, for example. For refactoring, that means that many changes can be completely automatic, with no need of confirmation from the developer.</p>
<p>When a method on class Foo changes from <code>bar()</code> to <code>baz()</code>, you can create a tool that goes through the entirety of the single Google repository, finds all instances of <em>that</em> Foo class and its subclasses, and changes all mentions of <code>bar()</code> to <code>baz()</code>. With Dart’s sound type system, you can be sure this won’t break anything. Without sound types, even such a simple change can get you in trouble.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/sqEj9IRiu2-jSIqsltS0Wuxx8CzTgNQQnfPJ" alt="Image" width="500" height="549" loading="lazy">
_One keystroke and your code is formatted according to Dart [style guide](https://www.dartlang.org/guides/language/effective-dart/style#formatting" rel="noopener" target="_blank" title="). In fact, the guide states: “The official whitespace-handling rules for Dart are <strong>whatever dart_style produces</strong>.”_</p>
<p>Another thing that helps with large scale changes is <a target="_blank" href="https://github.com/dart-lang/dart_style">dart_style</a>, Dart’s default formatter. All Dart code at Google is formatted using this tool. By the time your code reaches reviewers, it has been auto-formatted using dart_style, so there are no arguments about whether to put the newline here or there. And that applies to large scale refactors as well.</p>
<h3 id="heading-performance-metrics">Performance metrics</h3>
<p>As I said above, AngularDart benefits from its dependents’ tests. But it’s not just tests. Google is very rigorous about measuring performance of its apps, and so most (all?) production apps have benchmark suites.</p>
<p>So when the AngularDart team introduces a change that makes AdWords 1% slower to load, they know <em>before</em> landing the change. When the team <a target="_blank" href="https://www.youtube.com/watch?list=PLOU2XLYxmsILKY-A1kq4eHMcku3GMAyp2&amp;v=8ixOkJOXdMo">said</a> in October that AngularDart apps got 40% smaller and 10% faster since August, they were not talking about some synthetic tiny TodoMVC example apps. They were talking about real-life, mission-critical, production apps with millions of users and megabytes of business logic code.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/SysqQlFJA4f3ktY712-YfEXb1aQZNVTx5VRv" alt="Image" width="800" height="360" loading="lazy"></p>
<h3 id="heading-side-note-hermetic-build-tool">Side note: Hermetic build tool</h3>
<p>You may be wondering: how did this guy know which tests in the huge internal repository to run after introducing the flaky bug in AngularDart? Surely he wasn’t hand-picking the 74 thousand tests, and just as surely he wasn’t running <em>all</em> the tests at Google. The answer lies in something called Bazel.</p>
<p>At this scale, you can’t have a series of shell scripts to build stuff. Things would be flaky and prohibitively slow. What you need is a hermetic build tool.</p>
<p>“Hermetic” in this context is very similar to “<a target="_blank" href="https://en.wikipedia.org/wiki/Pure_function">pure</a>” in the context of functions. Your build steps cannot have side effects (like temp files, changes to PATH etc.), and they must be deterministic (same input always leads to the same output). When that’s the case, you can run the builds and the tests on any machine at any time and you’ll get consistent output. You don’t need to <code>make clean</code>. You can therefore send your builds/tests to build servers and parallelize them.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/KXMw3tOJf82-JlnAbi0topqlDoVK4UH1Gxxu" alt="Image" width="446" height="284" loading="lazy"></p>
<p>Google has spent years developing such a build tool. It was open sourced last year as <a target="_blank" href="https://bazel.build/">Bazel</a>.</p>
<p>And thanks to this piece of infrastructure, internal testing tools can determine which builds/tests each change affects, and run them when appropriate.</p>
<h3 id="heading-what-does-it-all-mean">What does it all mean?</h3>
<p>AngularDart’s explicit goal is to be best-in-class in productivity, performance and dependability for building large web applications. This post hopefully covers the last part — dependability — and why it’s important that mission-critical Google apps like AdWords and AdSense are using the framework. It’s not just the team boasting about their users — as explained above, having large internal users makes AngularDart less likely to introduce superficial changes. It makes the framework more dependable.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/fbVxJ2-4EeeKKTXhTRoWVEMZrpAVQBeVTgzV" alt="Image" width="800" height="310" loading="lazy">
_If this all sounds too business-y, you could check out my decidedly-non-business AngularDart projects like [Prime Finder](https://filiph.github.io/markov/" rel="noopener" target="_blank" title=""&gt;Automatic Donald Trump (Markov chain) or &lt;a href="https://filiph.github.io/prime_finder/" rel="noopener" target="<em>blank" title=").</em></p>
<p>If you’re looking for a framework that makes major overhauls and introduces major features every few months, AngularDart is definitely not for you. Even if the team wanted to build the framework in such a way, I think it’s clear from this article that they couldn’t. We sincerely believe, though, that there is space for a framework that is less trendy but dependable.</p>
<p>In my opinion, the best prediction of long-term support of an open-source tech stack is that it’s a big part of the primary maintainer’s business. Take Android, dagger, MySQL, or git as examples. That’s why I’m glad that Dart finally has one preferred web framework (AngularDart), one preferred component library (<a target="_blank" href="https://pub.dartlang.org/packages/angular2_components">AngularDart Components</a>) and one preferred mobile framework (<a target="_blank" href="https://flutter.io/">Flutter</a>) — all of which are used to build business-critical Google apps.</p>
<p><em>[<a target="_blank" href="https://medium.com/@matanlurey">Matan Lurey</a> and Kathy Walrath contributed to this article.]</em></p>
<p>_[Discuss on <a target="_blank" href="https://www.reddit.com/r/webdev/comments/5t6f8o/how_google_builds_a_web_framework/">Reddit</a>, <a target="_blank" href="https://news.ycombinator.com/item?id=13614354">HN</a>, <a target="_blank" href="https://twitter.com/filiphracek/status/829991585756520448">Twitter</a>.]_</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Angular Authentication made easy with Firebase ]]>
                </title>
                <description>
                    <![CDATA[ By Wassim Chegham UPDATE: The code in this article has been updated to Angular Final. We also assume that you’re using the latest Angular CLI. Any serious Web application requires some sort of authentication feature. In this blog post, we’ll set up... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/angular-2-authentication-made-easy-with-firebase-246c282d9ef8/</link>
                <guid isPermaLink="false">66c344a0160da468ed76f14d</guid>
                
                    <category>
                        <![CDATA[ angular2 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Firebase ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 07 Aug 2016 23:30:08 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*oOBXowI2IO9eCTcxP1BT-Q.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Wassim Chegham</p>
<blockquote>
<p>UPDATE: The code in this article has been updated to Angular Final. We also assume that you’re using the latest Angular CLI.</p>
</blockquote>
<p>Any serious Web application requires some sort of authentication feature. In this blog post, we’ll set up this feature for an Angular application using Firebase, thanks to the official <a target="_blank" href="https://github.com/angular/angularfire2">AngularFire2</a> library.</p>
<h3 id="heading-create-a-new-firebase-project">Create a new Firebase project</h3>
<p>Before using Firebase with our application, we need to create a new project in our <a target="_blank" href="https://console.firebase.google.com/">Firebase developer console</a>:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*ZzoMPcmlDgYRLCQgAFiU8Q.png" alt="Image" width="800" height="696" loading="lazy">
<em>Firebase Developer Console</em></p>
<p>To use the Firebase Authentication feature, we need to enable the <strong>sign-in providers</strong> we want to use in our project. In our case, we’re going to use Google, Facebook, Twitter and Github to log in our users.</p>
<p>You can find the Authentication page in: Your App → Auth → SIGN-IN METHOD:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*wfIpVAzDOEVFUJR2UjUp5g.png" alt="Image" width="800" height="712" loading="lazy"></p>
<p>Some providers, such as Facebook, Twitter and Github, require you to provide an <strong>App/Client/API ID</strong> and <strong>App/Client/API secret</strong> keys, and use the given <strong>OAuth URI</strong> as the redirect URI:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*cmB2uiqwESrHHwKo1RVkgA.png" alt="Image" width="800" height="696" loading="lazy"></p>
<p>In order to obtain this information, you will need to create one application for each provider using your developer account of each service (Github, Facebook and Twitter).</p>
<h3 id="heading-configure-your-services">Configure your services</h3>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*M372rrSgYuiwgODlftxKDQ.png" alt="Image" width="800" height="598" loading="lazy">
<em>Github Application Settings</em></p>
<p>For Github, go to your <a target="_blank" href="https://github.com/settings/developers">developer settings</a>, and <a target="_blank" href="https://github.com/settings/applications/new">register</a> a new application.</p>
<p>Use your application <strong>Client ID</strong> and <strong>Client Secret</strong> in your Firebase configuration page.</p>
<p>You also need to fill in the <strong>Authorization callback URL</strong> using the <strong>OAuth URI</strong> from Firebase.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*UsjnM5koHUhanSlGXYR6Yg.png" alt="Image" width="800" height="606" loading="lazy">
<em>Twitter Application Settings</em></p>
<p>For Twitter, go to your <a target="_blank" href="https://apps.twitter.com/">Application Management settings</a>, and <a target="_blank" href="https://apps.twitter.com/app/new">create a new</a> application.</p>
<p>Use your application <strong>API key</strong> and <strong>API Secret</strong> in your Firebase configuration page.</p>
<p>You also need to fill in the <strong>Callback URL</strong> (in the Settings tab) using the <strong>OAuth URI</strong> from Firebase.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*blTSqtexKVeShcVPDMHKaw.png" alt="Image" width="800" height="670" loading="lazy">
<em>Facebook Developer Console</em></p>
<p>Finally, for Facebook, go to your <a target="_blank" href="https://developers.facebook.com/apps/">developer apps</a> home page, and click on the “Add New App” green button at the upper-right corner.</p>
<p>Use your <strong>App ID</strong> and <strong>App Secret</strong> in your Firebase configuration page.</p>
<p>You also need to add a new Web platform. Click on <strong>+Add platform</strong> at the bottom of the page—and fill in the Site URL with the redirect URI from Firebase (i.e. <strong>OAuth URI</strong>).</p>
<p>Now you are ready to use Google, Twitter, Github and Facebook as your authentication providers for your web application.</p>
<h3 id="heading-use-angularfire-in-your-application">Use AngularFire in your application</h3>
<p>For the next step, I’m going to use an Angular application I scaffolded thanks to the <a target="_blank" href="https://github.com/angular/angular-cli">official Angular CLI</a>.</p>
<p>In this application, I’m going to use the Authentication providers we just set up in the previous step.</p>
<p>Here’s what the application looks like:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*wmQDx_-Q87Gr-nu9iFRXGg.png" alt="Image" width="552" height="771" loading="lazy"></p>
<p>Clicking on a button will call a specific provider, authenticate the user, and get their information:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*zgPhCyiM1Z93aWXD-u3__g.png" alt="Image" width="552" height="771" loading="lazy">
<em>User logged in using github.com</em></p>
<h4 id="heading-install-and-setup-angularfire2">Install and setup angularfire2</h4>
<p>First things first, we need to install the <em>firebase</em> and <em>angularfire2</em> libraries:</p>
<pre><code>$ npm install angularfire2 firebase --save
</code></pre><p>Then we need to install <em>Firebase</em> types:</p>
<pre><code>$ npm install @types/firebase
</code></pre><p>And add those types to your <strong>src/tsconfig.json</strong> file:</p>
<pre><code>{  <span class="hljs-string">"compilerOptions"</span>: {    <span class="hljs-string">"declaration"</span>: <span class="hljs-literal">false</span>,    <span class="hljs-string">"emitDecoratorMetadata"</span>: <span class="hljs-literal">true</span>,    <span class="hljs-string">"experimentalDecorators"</span>: <span class="hljs-literal">true</span>,    <span class="hljs-string">"lib"</span>: [<span class="hljs-string">"es6"</span>, <span class="hljs-string">"dom"</span>],    <span class="hljs-string">"mapRoot"</span>: <span class="hljs-string">"./"</span>,    <span class="hljs-string">"module"</span>: <span class="hljs-string">"es6"</span>,    <span class="hljs-string">"moduleResolution"</span>: <span class="hljs-string">"node"</span>,    <span class="hljs-string">"outDir"</span>: <span class="hljs-string">"../dist/out-tsc"</span>,    <span class="hljs-string">"sourceMap"</span>: <span class="hljs-literal">true</span>,    <span class="hljs-string">"target"</span>: <span class="hljs-string">"es5"</span>,    <span class="hljs-string">"typeRoots"</span>: [      <span class="hljs-string">"../node_modules/@types"</span>    ],    <span class="hljs-string">"types"</span>: [      <span class="hljs-string">"jasmine"</span>,      <span class="hljs-string">"firebase"</span>,      <span class="hljs-string">"node"</span>    ]  }}
</code></pre><p>A more detailed setup process is described in <a target="_blank" href="https://github.com/angular/angularfire2/blob/master/docs/1-install-and-setup.md">the official docs</a>.</p>
<h4 id="heading-configure-angularfire-for-your-application">Configure <em>AngularFire</em> for your Application</h4>
<p>In order to use Firebase with Angular, we need to provide some configuration for the AngularFire services.</p>
<p>Let’s start with the default Firebase configuration which looks like this:</p>
<pre><code>defaultFirebase({  <span class="hljs-attr">apiKey</span>: <span class="hljs-string">"AIzaSyCk3weREVFpOIN6pL_QVVNFRl3C3keMIRU"</span>,  <span class="hljs-attr">authDomain</span>: <span class="hljs-string">"angular2-auth.firebaseapp.com"</span>,  <span class="hljs-attr">databaseURL</span>: <span class="hljs-string">"https://angular2-auth.firebaseio.com"</span>,  <span class="hljs-attr">storageBucket</span>: <span class="hljs-string">"angular2-auth.appspot.com"</span>})
</code></pre><p><em>Note: Don’t worry about this exposed <strong>apiKey</strong>. This key is only used to identify the different services of your project: a kind of project identifier.</em></p>
<p>You can get your Firebase <strong>apiKey</strong>, <strong>projectId, databaseName,</strong> and <strong>bucket ID</strong> from your application dashboard.</p>
<p>Click on the <strong>WEB SETUP</strong> button in the top-right corner:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*qzOQlZJtR6U9luzBDaVwrw.png" alt="Image" width="800" height="712" loading="lazy"></p>
<p>Next, for our use case, we want to provide a default authentication method:</p>
<pre><code>firebaseAuthConfig({  <span class="hljs-attr">method</span>: AuthMethods.Popup})
</code></pre><p>Here, we choose to use a <strong>Popup</strong> to allow the user to log in. We could also use a Redirect method like this:</p>
<pre><code>firebaseAuthConfig({  <span class="hljs-attr">method</span>: AuthMethods.Redirect})
</code></pre><p>Let’s now create a <em>CoreModule</em> in <strong>src/app/core.module.ts</strong> where we will put our configuration. It is best practice to group core dependencies in a separate NgModule named <a target="_blank" href="https://angular.io/docs/ts/latest/guide/ngmodule.html#!#core-module">CoreModule</a>. Here is an example of such module:</p>
<pre><code><span class="hljs-keyword">import</span> { BrowserModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/platform-browser'</span>;<span class="hljs-keyword">import</span> { HttpModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/http'</span>;<span class="hljs-keyword">import</span> { NgModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;<span class="hljs-keyword">import</span> { FormsModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/forms'</span>;<span class="hljs-keyword">import</span> {   AngularFireModule,   AuthMethods,   AuthProviders } <span class="hljs-keyword">from</span> <span class="hljs-string">"angularfire2"</span>;
</code></pre><pre><code><span class="hljs-keyword">const</span> firebaseConfig = {  <span class="hljs-attr">apiKey</span>: <span class="hljs-string">"AIzaSyCk3weREVFpOIN6pL_QVVNFRl3C3keMIRU"</span>,  <span class="hljs-attr">authDomain</span>: <span class="hljs-string">"angular2-auth.firebaseapp.com"</span>,  <span class="hljs-attr">databaseURL</span>: <span class="hljs-string">"https://angular2-auth.firebaseio.com"</span>,  <span class="hljs-attr">storageBucket</span>: <span class="hljs-string">"angular2-auth.appspot.com"</span>};
</code></pre><pre><code>@NgModule({  <span class="hljs-attr">imports</span>: [    BrowserModule,    FormsModule,    HttpModule,    AngularFireModule.initializeApp(firebaseConfig,{      <span class="hljs-attr">provider</span>: AuthProviders.Google,      <span class="hljs-attr">method</span>: AuthMethods.Popup    })  ],  <span class="hljs-attr">exports</span>: [    BrowserModule,  ]})<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">CoreModule</span> </span>{}
</code></pre><h4 id="heading-using-it-in-your-components">Using it in your components</h4>
<p>Now we’re finally ready to implement the authentication feature for our Angular application.</p>
<p>We need to inject the <strong>AngularFire</strong> service in the component’s constructor:</p>
<pre><code><span class="hljs-keyword">import</span> { Component } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;<span class="hljs-keyword">import</span> { AngularFire, AuthProviders } <span class="hljs-keyword">from</span> <span class="hljs-string">'angularfire2'</span>;
</code></pre><pre><code>@Component({  <span class="hljs-attr">moduleId</span>: <span class="hljs-built_in">module</span>.id,  <span class="hljs-attr">selector</span>: <span class="hljs-string">'app-root'</span>,  <span class="hljs-attr">templateUrl</span>: <span class="hljs-string">'app.component.html'</span>,  <span class="hljs-attr">styleUrls</span>: [<span class="hljs-string">'app.component.css'</span>]})<span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppComponent</span> </span>{  user = {};
</code></pre><pre><code>  <span class="hljs-keyword">constructor</span>(    public af: AngularFire  ) {    <span class="hljs-built_in">this</span>.af.auth.subscribe(<span class="hljs-function"><span class="hljs-params">user</span> =&gt;</span> {      <span class="hljs-keyword">if</span>(user) {        <span class="hljs-comment">// user logged in        this.user = user;      }      else {        // user not logged in        this.user = {};      }    });  }}</span>
</code></pre><blockquote>
<p>In a real world application, you would create a separate service that handles authentication. Think <a target="_blank" href="https://en.wikipedia.org/wiki/Single_responsibility_principle">SRP</a> and <a target="_blank" href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY</a>. But for this tutorial, we will keep it simple.</p>
</blockquote>
<p>The <strong>AngularFire</strong> service gives us the <strong>auth</strong> property which implements the Observable API. So that means we need to subscribe to this <strong>auth</strong> property in order to get the authentication state. A <strong><em>NULL</em></strong> value means the user is not logged in.</p>
<p>Let’s add a couple of buttons in the component’s view:</p>
<pre><code>&lt;button md-raised-button (click)=<span class="hljs-string">"login()"</span>&gt;  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">width</span>=<span class="hljs-string">"30"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"google-logo.png"</span> /&gt;</span></span>Use My Google Account&lt;<span class="hljs-regexp">/button&gt;&lt;button md-raised-button (click)="logout()"&gt;  Logout&lt;/</span>button&gt;
</code></pre><p>We will use those buttons to log in and log out, using the Google provider as an example.</p>
<p>In <strong><em>app.component.ts</em></strong>, we need to implement the <strong><em>login()</em></strong> <em>and <strong>logout()</strong></em> methods:</p>
<pre><code>login() {  <span class="hljs-built_in">this</span>.af.auth.login({    <span class="hljs-attr">provider</span>: AuthProviders.Google  });} logout() {  <span class="hljs-built_in">this</span>.af.auth.logout();}
</code></pre><p>To log a user in, we call the <strong>this.af.auth.login()</strong> method using the Google provider, and <strong>this.af.auth.logout()</strong> to log a user out.</p>
<p>The <strong>AngulareFire login()</strong> usually needs an authentication method. In our case, it will use the default method (i.e. <strong>AuthMethods.Popup)</strong> we set up in the bootstrap phase.</p>
<p>If you need to override the authentication method when calling the <strong>login()</strong> method, just provide a new auth configuration:</p>
<pre><code>login() {  <span class="hljs-built_in">this</span>.af.auth.login({    <span class="hljs-attr">provider</span>: AuthProviders.Google,    <span class="hljs-attr">method</span>: AuthMethods.Redirect  });}
</code></pre><p>Once everything is setup and working correctly, we can inspect the <strong><em>user</em></strong> object containing all the user’s session tokens sent by Google (the authentication provider):</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*mQcUhIAo_anodDNp_Z0tnQ.png" alt="Image" width="800" height="1063" loading="lazy"></p>
<p>You can get the user’s information such the <strong>displayName</strong> and the <strong>photoURL</strong> form the <strong>auth.provideData</strong> entry.</p>
<p>That’s it! Your users can now log in using their Google accounts.</p>
<p>You can add Github and Facebook in much the same way.</p>
<p>See the complete working application <a target="_blank" href="https://angular2-auth.firebaseapp.com">hosted on Firebase</a> or read the complete source code <a target="_blank" href="https://github.com/manekinekko/angular-firebase-authentication">on Github</a>.</p>
<blockquote>
<p>NOTE: I’m in the process of migration this repo to Angular final (<a target="_blank" href="https://github.com/manekinekko/angular-firebase-authentication/tree/migration-to-angular-2.0.0">see branch</a>). This process is pending because of <a target="_blank" href="https://github.com/manekinekko/angular-firebase-authentication/issues/3">this issue</a> in AngularFire2.</p>
</blockquote>
<p><a target="_blank" href="https://github.com/manekinekko/angular-firebase-authentication"><strong>manekinekko/angular-firebase-authentication</strong></a><br><a target="_blank" href="https://github.com/manekinekko/angular-firebase-authentication">_angular-firebase-authentication - An angular demoing Firebase Authentication providers_github.com</a></p>
<h3 id="heading-tips-amp-references">Tips &amp; References</h3>
<p><em>Follow <a target="_blank" href="https://twitter.com/manekinekko">@manekinekko</a> to learn more about the web platform.</em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
