<?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[ angular 5 - 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[ angular 5 - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Thu, 02 Jul 2026 17:25:32 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/angular-5/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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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="600" height="400" 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 deploy editable tables in HTML using Angular 5 and Entity Framework Core ]]>
                </title>
                <description>
                    <![CDATA[ By Ankit Sharma Introduction In this article, we are going to create a web application using ASP.NET Core 2.0 and Angular 5 with the help of the Entity Framework (EF) Core database-first approach. We will be creating a sample Employee Record Manageme... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/asp-net-core-crud-using-angular-5-and-entity-framework-core-374ac04cd3ec/</link>
                <guid isPermaLink="false">66d45d9cc7632f8bfbf1e3d9</guid>
                
                    <category>
                        <![CDATA[ angular 5 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ entity framework core ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web Development ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 18 Apr 2018 05:56:43 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*W5vbBi1Nah40KGMRIE1GJw.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Ankit Sharma</p>
<h3 id="heading-introduction">Introduction</h3>
<p>In this article, we are going to create a web application using <strong>ASP.NET Core 2.0</strong> and <strong>Angular 5</strong> with the help of the Entity Framework (EF) Core database-first approach. We will be creating a sample Employee Record Management system. To read the inputs from the user, we will use <strong>Angular forms</strong> with required field validations on the client side. We are also going to bind a dropdown list in the Angular form to a table in the database using EF Core.</p>
<p>We will be using <strong>Visual Studio 2017</strong> and <strong>SQL Server</strong> version 2008 or above.</p>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ul>
<li>Install .NET Core 2.0.0 or above SDK from <a target="_blank" href="https://www.microsoft.com/net/core#windowscmd">here</a>.</li>
<li>Install the latest version of Visual Studio 2017 Community Edition from <a target="_blank" href="https://www.visualstudio.com/downloads/">here</a>.</li>
<li>Download and install the latest version of Node.js from <a target="_blank" href="https://nodejs.org/en/download/">here</a>..</li>
<li>SQL Server 2008 or above.</li>
</ul>
<h3 id="heading-source-code">Source Code</h3>
<p>Before proceeding, I recommend you get the source code from <a target="_blank" href="https://github.com/AnkitSharma-007/CRUD.ASPCore.Angular5.WebAPI.EF">Github</a>.</p>
<h3 id="heading-creating-the-tables">Creating the tables</h3>
<p>We will be using two tables to store our data.</p>
<ol>
<li><code>tblEmployee</code>: used to store the details of employees. It contains fields such as EmployeeID, Name, City, Department, and Gender.</li>
<li><code>tblCities</code>: this contains the list of cities. It is used to populate the <em>City</em> field of the tblEmployee table. tblCities contains two fields, CityID and CityName.</li>
</ol>
<p>Execute the following commands to create both tables:</p>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> tblEmployee (  EmployeeID <span class="hljs-built_in">int</span> <span class="hljs-keyword">IDENTITY</span>(<span class="hljs-number">1</span>,<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> PRIMARY <span class="hljs-keyword">KEY</span>,  <span class="hljs-keyword">Name</span> <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> ,  City <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> ,  Department <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> ,  Gender <span class="hljs-built_in">varchar</span>(<span class="hljs-number">6</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>   )  <span class="hljs-keyword">GO</span>    <span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> tblCities (  CityID <span class="hljs-built_in">int</span> <span class="hljs-keyword">IDENTITY</span>(<span class="hljs-number">1</span>,<span class="hljs-number">1</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span> PRIMARY <span class="hljs-keyword">KEY</span>,  CityName <span class="hljs-built_in">varchar</span>(<span class="hljs-number">20</span>) <span class="hljs-keyword">NOT</span> <span class="hljs-literal">NULL</span>   )  <span class="hljs-keyword">GO</span>
</code></pre>
<p>Now we will put some data into the <code>tblCities</code> table. We will be using this table to bind a dropdown list in our web application. The desired city can be selected using this dropdown list. Use the following insert statements.</p>
<pre><code class="lang-sql"><span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> tblCities <span class="hljs-keyword">VALUES</span>(<span class="hljs-string">'New Delhi'</span>);  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> tblCities <span class="hljs-keyword">VALUES</span>(<span class="hljs-string">'Mumbai'</span>);  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> tblCities <span class="hljs-keyword">VALUES</span>(<span class="hljs-string">'Hyderabad'</span>);  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> tblCities <span class="hljs-keyword">VALUES</span>(<span class="hljs-string">'Chennai'</span>);  <span class="hljs-keyword">INSERT</span> <span class="hljs-keyword">INTO</span> tblCities <span class="hljs-keyword">VALUES</span>(<span class="hljs-string">'Bengaluru'</span>);
</code></pre>
<p>Now, our Database part has been completed. So, we will proceed to create the MVC application using Visual Studio 2017.</p>
<h3 id="heading-create-the-aspnet-mvc-web-application">Create the ASP.NET MVC web application</h3>
<p>Open Visual Studio and select File &gt;&gt; New &gt;&gt; Project.</p>
<p>After selecting the project, a “New Project” dialog will open. Select .NET Core inside Visual C# menu from the left panel.</p>
<p>Then, select “ASP.NET Core Web Application” from the available project types. Put the name of the project as “EFNgApp” and press OK.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/YVcPWRXi6XvKor9-rq6xKvKl1Q9D5E90SDEi" alt="Image" width="650" height="397" loading="lazy"></p>
<p>After clicking on OK, a new dialog will open asking you to select the project template. You can observe two drop-down menus at the top left of the template window. Select “.NET Core” and “ASP.NET Core 2.0” from these dropdowns. Then, select the “Angular” template and press OK.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/K6YQvZWOFaTVBg9tQW-2ZgTokPtEbaAyxbNC" alt="Image" width="650" height="425" loading="lazy"></p>
<p>Now, our project will be created. You can see the folder structure in Solution Explorer in the below image.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/iCGpODkNimBqGNlUVEJPy0468-Rnjv7-N1ih" alt="Image" width="245" height="520" loading="lazy"></p>
<p>Here, we have our “Controllers” and “Views” folders. We won’t be touching the Views folder for this tutorial, since we will be using Angular to handle the UI.</p>
<p>The <em>Controllers</em> folders will contain our Web API controller. The point of interest for us is the “ClientApp” folder where the client side of our application resides.</p>
<p>Inside the “ClientApp/app/components folder,” we already have few components created. These are provided by default with the Angular template in VS 2017. These components won’t affect our application, but for the sake of this tutorial, we will delete the “fetchdata” and “counter” folders from ClientApp/app/components<em>.</em></p>
<h3 id="heading-adding-the-model-to-the-application">Adding the Model to the Application</h3>
<p>We are using Entity Framework core database first approach to create our models. Navigate to Tools &gt;&gt; NuGet Package Manager &gt;&gt; Package Manager Console.</p>
<p>We have to install the package for the database provider that we are targeting, which is SQL Server in this case. Now run the following command:</p>
<pre><code>Install-Package Microsoft.EntityFrameworkCore.SqlServer
</code></pre><p>Since we are using Entity Framework Tools to create a model from the existing database, we will install the tools package as well. Run the following command:</p>
<pre><code>Install-Package Microsoft.EntityFrameworkCore.Tools
</code></pre><p>After you have installed both the packages, we will scaffold our model from the database tables using the following command:</p>
<pre><code>Scaffold-DbContext <span class="hljs-string">"Your connection string here"</span> Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Tables tblEmployee, tblCities
</code></pre><p><strong>Do not forget</strong> to put your own connection string (inside double quotes “ ”). After this command gets executed successfully, a “Models” folder will be created. This folder contains three class files: <code>myTestDBContext.cs</code><em>,</em> <code>TblCities.cs</code> and <code>TblEmployee.cs</code>. We have successfully created our Models using EF core database first approach.</p>
<p>Now, we will create one more class file to handle database related operations</p>
<p>Right click on the “Models” folder and select Add &gt;&gt; Class. Name your <code>class EmployeeDataAccessLa</code>_y_er.cs and click the “Add” button. At this point, the “Models” folder will have the following structure.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/bovuU80LNmD-dy2hiWJTqQ5N11RnqoiFv4Oa" alt="Image" width="248" height="398" loading="lazy"></p>
<p>Open “EmployeeDataAccessLayer.cs” and insert the following code to handle database operations.</p>
<pre><code>using Microsoft.EntityFrameworkCore;  using System;  using System.Collections.Generic;  using System.Linq;  using System.Threading.Tasks;    namespace EFNgApp.Models  {      public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmployeeDataAccessLayer</span>      </span>{          myTestDBContext db = <span class="hljs-keyword">new</span> myTestDBContext();            public IEnumerable&lt;TblEmployee&gt; GetAllEmployees()          {              <span class="hljs-keyword">try</span>              {                  <span class="hljs-keyword">return</span> db.TblEmployee.ToList();              }              <span class="hljs-keyword">catch</span>              {                  <span class="hljs-keyword">throw</span>;              }          }            <span class="hljs-comment">//To Add new employee record           public int AddEmployee(TblEmployee employee)          {              try              {                  db.TblEmployee.Add(employee);                  db.SaveChanges();                  return 1;              }              catch              {                  throw;              }          }            //To Update the records of a particluar employee          public int UpdateEmployee(TblEmployee employee)          {              try              {                  db.Entry(employee).State = EntityState.Modified;                  db.SaveChanges();                    return 1;              }              catch              {                  throw;              }          }            //Get the details of a particular employee          public TblEmployee GetEmployeeData(int id)          {              try              {                  TblEmployee employee = db.TblEmployee.Find(id);                  return employee;              }              catch              {                  throw;              }          }            //To Delete the record of a particular employee          public int DeleteEmployee(int id)          {              try              {                  TblEmployee emp = db.TblEmployee.Find(id);                  db.TblEmployee.Remove(emp);                  db.SaveChanges();                  return 1;              }              catch              {                  throw;              }          }            //To Get the list of Cities          public List&lt;TblCities&gt; GetCities()          {              List&lt;TblCities&gt; lstCity = new List&lt;TblCities&gt;();              lstCity = (from CityList in db.TblCities select CityList).ToList();                return lstCity;          }      }  }</span>
</code></pre><p>Now, we will proceed to create our Web API Controller.</p>
<h3 id="heading-adding-the-web-api-controller-to-the-application">Adding the Web API Controller to the Application</h3>
<p>Right click on Controllers folder and select Add &gt;&gt; New Item.</p>
<p>An “Add New Item” dialog box will open. Select “ASP.NET<em>”</em> from the left panel. Then, select “Web API Controller Class” from templates panel and put the name as <code>EmployeeController.cs</code>. Click “Add”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/q623LWrLWzNKZSYDuGzALTxR0OxuLWmYey-G" alt="Image" width="650" height="397" loading="lazy"></p>
<p>This will create our Web API “EmployeeController” class. We will put all our business logic in this controller. We will call the methods of “EmployeeDataAccessLayer” to fetch data and pass on the data to the Angular frontend.</p>
<p>Open the “EmployeeController.cs” file and insert the following code into it:</p>
<pre><code>using System;  using System.Collections.Generic;  using System.Linq;  using System.Threading.Tasks;  using EFNgApp.Models;  using Microsoft.AspNetCore.Mvc;     namespace EFNgApp.Controllers  {        public <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmployeeController</span> : <span class="hljs-title">Controller</span>      </span>{          EmployeeDataAccessLayer objemployee = <span class="hljs-keyword">new</span> EmployeeDataAccessLayer();            [HttpGet]          [Route(<span class="hljs-string">"api/Employee/Index"</span>)]          public IEnumerable&lt;TblEmployee&gt; Index()          {              <span class="hljs-keyword">return</span> objemployee.GetAllEmployees();          }            [HttpPost]          [Route(<span class="hljs-string">"api/Employee/Create"</span>)]          public int Create([FromBody] TblEmployee employee)          {              <span class="hljs-keyword">return</span> objemployee.AddEmployee(employee);          }            [HttpGet]          [Route(<span class="hljs-string">"api/Employee/Details/{id}"</span>)]          public TblEmployee Details(int id)          {              <span class="hljs-keyword">return</span> objemployee.GetEmployeeData(id);          }            [HttpPut]          [Route(<span class="hljs-string">"api/Employee/Edit"</span>)]          public int Edit([FromBody]TblEmployee employee)          {              <span class="hljs-keyword">return</span> objemployee.UpdateEmployee(employee);          }            [HttpDelete]          [Route(<span class="hljs-string">"api/Employee/Delete/{id}"</span>)]          public int Delete(int id)          {              <span class="hljs-keyword">return</span> objemployee.DeleteEmployee(id);          }            [HttpGet]          [Route(<span class="hljs-string">"api/Employee/GetCityList"</span>)]          public IEnumerable&lt;TblCities&gt; Details()          {              <span class="hljs-keyword">return</span> objemployee.GetCities();          }      }  }
</code></pre><p>We are done with our backend logic. Now we’ll code our frontend using Angular 5.</p>
<h3 id="heading-create-the-angular-service">Create the Angular Service</h3>
<p>We will create an Angular service which will convert the Web API response to JSON and pass it to our component.</p>
<p>Right-click on the “ClientApp/app” folder and then Add &gt;&gt; New Folder and name the folder as “Services”.</p>
<p>Right-click on the “Services” folder and select Add &gt;&gt; New Item. An “Add New Item” dialog box will open. Select “Scripts” from the left panel. Then select “TypeScript File” from the templates panel, and put the na<code>me as empservice.serv</code>ice.ts. Click “Add”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/XNeVx14RTmuHKuPLcemx4ZKNwivkQCYLY0kX" alt="Image" width="650" height="397" loading="lazy"></p>
<p>Open the “empservice.service.ts” file and insert the following code into it:</p>
<pre><code><span class="hljs-keyword">import</span> { Injectable, Inject } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;  <span class="hljs-keyword">import</span> { Http, Response } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/http'</span>;  <span class="hljs-keyword">import</span> { Observable } <span class="hljs-keyword">from</span> <span class="hljs-string">'rxjs/Observable'</span>;  <span class="hljs-keyword">import</span> { Router } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/router'</span>;  <span class="hljs-keyword">import</span> <span class="hljs-string">'rxjs/add/operator/map'</span>;  <span class="hljs-keyword">import</span> <span class="hljs-string">'rxjs/add/operator/catch'</span>;  <span class="hljs-keyword">import</span> <span class="hljs-string">'rxjs/add/observable/throw'</span>;    @Injectable()  <span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">EmployeeService</span> </span>{      myAppUrl: string = <span class="hljs-string">""</span>;        <span class="hljs-keyword">constructor</span>(private _http: Http, @Inject('BASE_URL') baseUrl: string) {          <span class="hljs-built_in">this</span>.myAppUrl = baseUrl;      }        getCityList() {          <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>._http.get(<span class="hljs-built_in">this</span>.myAppUrl + <span class="hljs-string">'api/Employee/GetCityList'</span>)              .map(<span class="hljs-function"><span class="hljs-params">res</span> =&gt;</span> res.json())              .catch(<span class="hljs-built_in">this</span>.errorHandler);      }        getEmployees() {          <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>._http.get(<span class="hljs-built_in">this</span>.myAppUrl + <span class="hljs-string">'api/Employee/Index'</span>)              .map(<span class="hljs-function">(<span class="hljs-params">response: Response</span>) =&gt;</span> response.json())              .catch(<span class="hljs-built_in">this</span>.errorHandler);      }        getEmployeeById(id: number) {          <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>._http.get(<span class="hljs-built_in">this</span>.myAppUrl + <span class="hljs-string">"api/Employee/Details/"</span> + id)              .map(<span class="hljs-function">(<span class="hljs-params">response: Response</span>) =&gt;</span> response.json())              .catch(<span class="hljs-built_in">this</span>.errorHandler)      }        saveEmployee(employee) {          <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>._http.post(<span class="hljs-built_in">this</span>.myAppUrl + <span class="hljs-string">'api/Employee/Create'</span>, employee)              .map(<span class="hljs-function">(<span class="hljs-params">response: Response</span>) =&gt;</span> response.json())              .catch(<span class="hljs-built_in">this</span>.errorHandler)      }        updateEmployee(employee) {          <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>._http.put(<span class="hljs-built_in">this</span>.myAppUrl + <span class="hljs-string">'api/Employee/Edit'</span>, employee)              .map(<span class="hljs-function">(<span class="hljs-params">response: Response</span>) =&gt;</span> response.json())              .catch(<span class="hljs-built_in">this</span>.errorHandler);      }        deleteEmployee(id) {          <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>._http.delete(<span class="hljs-built_in">this</span>.myAppUrl + <span class="hljs-string">"api/Employee/Delete/"</span> + id)              .map(<span class="hljs-function">(<span class="hljs-params">response: Response</span>) =&gt;</span> response.json())              .catch(<span class="hljs-built_in">this</span>.errorHandler);      }        errorHandler(error: Response) {          <span class="hljs-built_in">console</span>.log(error);          <span class="hljs-keyword">return</span> Observable.throw(error);      }  }
</code></pre><p>At this point, you might get the following error: “Parameter ‘employee’ implicitly has an ‘any’ type” in “empservice.service.ts” file.</p>
<p>If you encounter this issue, then add the following line inside the “tsconfig.json” file.</p>
<p>“noImplicitAny”: false</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/d7o16eoU-aQFvrJ34miiRbbQTDUGkUZ5cObG" alt="Image" width="303" height="283" loading="lazy"></p>
<p>Now, we will create our components.</p>
<h3 id="heading-creating-angular-components">Creating Angular components</h3>
<p>We will be adding two Angular components to our application:</p>
<ol>
<li><code>fetchemployee</code> component: to display all the employee data or delete existing employee data.</li>
<li><code>addemployee</code> component: to add a new employee data or edit an existing employee data.</li>
</ol>
<p>Right-click on the “ClientApp/app/components” folder and select Add &gt;&gt; New Folder and name the folder “addem_p_loyee”.</p>
<p>Right-click on the “addemployee” folder, and select Add &gt;&gt; New Item. An “Add New Item” dialog box will open.</p>
<p>Select “Scripts<em>”</em> from the left panel, then select “TypeScript File” from templates panel. Put the name as <code>addemployee.component.ts</code>.</p>
<p>Click “Add”. This will add a typescript file inside the “addemployee” folder.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/AcmOw3ktlM2vZn8ifpuABDRetETxUyQ0UrsE" alt="Image" width="650" height="397" loading="lazy"></p>
<p>Right-click on the “addemployee” folder and select Add &gt;&gt; New Item. An “Add New Item” dialog box will open.</p>
<p>Select “ASP.NET Core<em>”</em> from the left panel, then select “HTML Page” from templates panel. Put the name as <code>addemployee.component.html</code><em>.</em></p>
<p>Click “Add”. This will add a HTML file inside the “addemployee” folder.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/k6398O41ak2SjjKxGswS6tb00SvfqIgGtI8q" alt="Image" width="650" height="397" loading="lazy"></p>
<p>Similarly, create a “fetchemployee” folder inside the “ClientApp/app/components” folder.</p>
<p>Add <code>fetchemployee.component.ts</code> and <code>fetchemployee.component.html</code> files to it.</p>
<p>Now our “ClientApp/app/components” structure will look like the image below.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1Ui2XGkgtU7CYRm0Jexoqrz4ZjhI89hYDTul" alt="Image" width="311" height="320" loading="lazy"></p>
<p>Open <code>fetchemployee.component.ts</code> and insert the following code:</p>
<pre><code><span class="hljs-keyword">import</span> { Component, Inject } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;  <span class="hljs-keyword">import</span> { Http, Headers } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/http'</span>;  <span class="hljs-keyword">import</span> { Router, ActivatedRoute } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/router'</span>;  <span class="hljs-keyword">import</span> { EmployeeService } <span class="hljs-keyword">from</span> <span class="hljs-string">'../../services/empservice.service'</span>    @Component({      <span class="hljs-attr">templateUrl</span>: <span class="hljs-string">'./fetchemployee.component.html'</span>  })    <span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FetchEmployeeComponent</span> </span>{      public empList: EmployeeData[];        <span class="hljs-keyword">constructor</span>(public http: Http, private _router: Router, private _employeeService: EmployeeService) {          <span class="hljs-built_in">this</span>.getEmployees();      }        getEmployees() {          <span class="hljs-built_in">this</span>._employeeService.getEmployees().subscribe(              <span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> <span class="hljs-built_in">this</span>.empList = data          )      }        <span class="hljs-keyword">delete</span>(employeeID) {          <span class="hljs-keyword">var</span> ans = confirm(<span class="hljs-string">"Do you want to delete customer with Id: "</span> + employeeID);          <span class="hljs-keyword">if</span> (ans) {              <span class="hljs-built_in">this</span>._employeeService.deleteEmployee(employeeID).subscribe(<span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> {                  <span class="hljs-built_in">this</span>.getEmployees();              }, <span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">console</span>.error(error))          }      }  }    interface EmployeeData {      <span class="hljs-attr">employeeId</span>: number;      name: string;      gender: string;      city: string;      department: string;    }
</code></pre><p>Let’s understand this code.</p>
<p>At the very top we have imported Angular modules and EmployeeService references. After this we use <code>@Component</code> decorator to define the template URL for our component.</p>
<p>Inside the <code>FetchEmployeeComponent</code> class we have declared an array variable <code>empList</code> of type <code>EmployeeData</code><em>.</em> <code>EmployeeData</code> is an interface having the properties same as our <code>TblEmployeeModel</code> class.</p>
<p>Inside the <code>getEmployees</code> method we are calling the <code>getEmployees</code> method of our service <code>EmployeeService</code>. This will return an array of <code>Employees</code> to be stored in the <code>empList</code> variable. The <code>getEmployees</code> method is called inside the constructor, so that the employee data will be displayed as the page loads.</p>
<p>Next, we have a <code>delete</code> method which accepts <code>employeeID</code> as a parameter. This will prompt the user with a confirmation box. If the user selects “yes” then it will delete the employee with this employeeID.</p>
<p>Open <code>fetchemployee.component.html</code> and insert the following code:</p>
<pre><code>&lt;h1&gt;Employee Data&lt;<span class="hljs-regexp">/h1&gt;    &lt;p&gt;This component demonstrates fetching Employee data from the server.&lt;/</span>p&gt;    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span> *<span class="hljs-attr">ngIf</span>=<span class="hljs-string">"!empList"</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">em</span>&gt;</span>Loading...<span class="hljs-tag">&lt;/<span class="hljs-name">em</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> [<span class="hljs-attr">routerLink</span>]=<span class="hljs-string">"['/register-employee']"</span>&gt;</span>Create New<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span></span>    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">table</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'table'</span> *<span class="hljs-attr">ngIf</span>=<span class="hljs-string">"empList"</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">thead</span>&gt;</span>          <span class="hljs-tag">&lt;<span class="hljs-name">tr</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>EmployeeId<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Name<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Gender<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>Department<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">th</span>&gt;</span>City<span class="hljs-tag">&lt;/<span class="hljs-name">th</span>&gt;</span>          <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>      <span class="hljs-tag">&lt;/<span class="hljs-name">thead</span>&gt;</span>      <span class="hljs-tag">&lt;<span class="hljs-name">tbody</span>&gt;</span>          <span class="hljs-tag">&lt;<span class="hljs-name">tr</span> *<span class="hljs-attr">ngFor</span>=<span class="hljs-string">"let emp of empList"</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ emp.employeeId }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ emp.name }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ emp.gender }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ emp.department }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>{{ emp.city }}<span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">td</span>&gt;</span>                  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> [<span class="hljs-attr">routerLink</span>]=<span class="hljs-string">"['/employee/edit/', emp.employeeId]"</span>&gt;</span>Edit<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span> |                  <span class="hljs-tag">&lt;<span class="hljs-name">a</span> [<span class="hljs-attr">routerLink</span>]=<span class="hljs-string">""</span> (<span class="hljs-attr">click</span>)=<span class="hljs-string">"delete(emp.employeeId)"</span>&gt;</span>Delete<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>              <span class="hljs-tag">&lt;/<span class="hljs-name">td</span>&gt;</span>          <span class="hljs-tag">&lt;/<span class="hljs-name">tr</span>&gt;</span>      <span class="hljs-tag">&lt;/<span class="hljs-name">tbody</span>&gt;</span>  <span class="hljs-tag">&lt;/<span class="hljs-name">table</span>&gt;</span></span>
</code></pre><p>The code for this HTML file is pretty simple.</p>
<p>At the top it has a link to create new employee record. After that it has a table to display employee data, and two links for editing and deleting each employee record.</p>
<p>We are finished with our <code>fetchemployee</code> component.</p>
<p>Now open <code>addemployee.component.ts</code> and insert the following code.</p>
<pre><code><span class="hljs-keyword">import</span> { Component, OnInit } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/core'</span>;  <span class="hljs-keyword">import</span> { Http, Headers } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/http'</span>;  <span class="hljs-keyword">import</span> { NgForm, FormBuilder, FormGroup, Validators, FormControl } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/forms'</span>;  <span class="hljs-keyword">import</span> { Router, ActivatedRoute } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/router'</span>;  <span class="hljs-keyword">import</span> { FetchEmployeeComponent } <span class="hljs-keyword">from</span> <span class="hljs-string">'../fetchemployee/fetchemployee.component'</span>;  <span class="hljs-keyword">import</span> { EmployeeService } <span class="hljs-keyword">from</span> <span class="hljs-string">'../../services/empservice.service'</span>;    @Component({      <span class="hljs-attr">templateUrl</span>: <span class="hljs-string">'./AddEmployee.component.html'</span>  })    <span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">createemployee</span> <span class="hljs-title">implements</span> <span class="hljs-title">OnInit</span> </span>{      employeeForm: FormGroup;      title: string = <span class="hljs-string">"Create"</span>;      employeeId: number;      errorMessage: any;      cityList: <span class="hljs-built_in">Array</span>&lt;any&gt; = [];        <span class="hljs-keyword">constructor</span>(private _fb: FormBuilder, private _avRoute: ActivatedRoute,          private _employeeService: EmployeeService, private _router: Router) {          <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>._avRoute.snapshot.params[<span class="hljs-string">"id"</span>]) {              <span class="hljs-built_in">this</span>.employeeId = <span class="hljs-built_in">this</span>._avRoute.snapshot.params[<span class="hljs-string">"id"</span>];          }            <span class="hljs-built_in">this</span>.employeeForm = <span class="hljs-built_in">this</span>._fb.group({              <span class="hljs-attr">employeeId</span>: <span class="hljs-number">0</span>,              <span class="hljs-attr">name</span>: [<span class="hljs-string">''</span>, [Validators.required]],              <span class="hljs-attr">gender</span>: [<span class="hljs-string">''</span>, [Validators.required]],              <span class="hljs-attr">department</span>: [<span class="hljs-string">''</span>, [Validators.required]],              <span class="hljs-attr">city</span>: [<span class="hljs-string">''</span>, [Validators.required]]          })      }        ngOnInit() {            <span class="hljs-built_in">this</span>._employeeService.getCityList().subscribe(              <span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> <span class="hljs-built_in">this</span>.cityList = data          )            <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.employeeId &gt; <span class="hljs-number">0</span>) {              <span class="hljs-built_in">this</span>.title = <span class="hljs-string">"Edit"</span>;              <span class="hljs-built_in">this</span>._employeeService.getEmployeeById(<span class="hljs-built_in">this</span>.employeeId)                  .subscribe(<span class="hljs-function"><span class="hljs-params">resp</span> =&gt;</span> <span class="hljs-built_in">this</span>.employeeForm.setValue(resp)                  , <span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">this</span>.errorMessage = error);          }        }        save() {            <span class="hljs-keyword">if</span> (!<span class="hljs-built_in">this</span>.employeeForm.valid) {              <span class="hljs-keyword">return</span>;          }            <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.title == <span class="hljs-string">"Create"</span>) {              <span class="hljs-built_in">this</span>._employeeService.saveEmployee(<span class="hljs-built_in">this</span>.employeeForm.value)                  .subscribe(<span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> {                      <span class="hljs-built_in">this</span>._router.navigate([<span class="hljs-string">'/fetch-employee'</span>]);                  }, <span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">this</span>.errorMessage = error)          }          <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-built_in">this</span>.title == <span class="hljs-string">"Edit"</span>) {              <span class="hljs-built_in">this</span>._employeeService.updateEmployee(<span class="hljs-built_in">this</span>.employeeForm.value)                  .subscribe(<span class="hljs-function">(<span class="hljs-params">data</span>) =&gt;</span> {                      <span class="hljs-built_in">this</span>._router.navigate([<span class="hljs-string">'/fetch-employee'</span>]);                  }, <span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> <span class="hljs-built_in">this</span>.errorMessage = error)          }      }        cancel() {          <span class="hljs-built_in">this</span>._router.navigate([<span class="hljs-string">'/fetch-employee'</span>]);      }        <span class="hljs-keyword">get</span> <span class="hljs-title">name</span>() { <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.employeeForm.get(<span class="hljs-string">'name'</span>); }      <span class="hljs-keyword">get</span> <span class="hljs-title">gender</span>() { <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.employeeForm.get(<span class="hljs-string">'gender'</span>); }      <span class="hljs-keyword">get</span> <span class="hljs-title">department</span>() { <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.employeeForm.get(<span class="hljs-string">'department'</span>); }      <span class="hljs-keyword">get</span> <span class="hljs-title">city</span>() { <span class="hljs-keyword">return</span> <span class="hljs-built_in">this</span>.employeeForm.get(<span class="hljs-string">'city'</span>); }  }
</code></pre><p>This component will be used for both adding and editing the employee data.</p>
<p>Since we are using a form model, along with client-side validation to add and edit employee data, we have imported classes from @angular/forms. The code to create the form has been put inside the constructor so that the form will be displayed as the page loads.</p>
<p>This component will handle both add and edit requests. So how will the system differentiate between both requests? The answer is routing. We need to define two different route parameters. One is for adding employee records. The other is for editing employee records. These route parameters will be defined in <code>app.shared.module.ts</code> in the following section.</p>
<p>We have declared the variable <code>title</code> to show on the top of the page and variable <code>id</code> to store the employee id passed as the parameter in case of an edit request. To read the employee ID from the URL we will use <code>ActivatedRoute.snapshot</code> inside the constructor, and set the value of variable <code>id</code>.</p>
<p>Inside <code>ngOnInit</code> we are performing two operations:</p>
<ol>
<li>We are fetching the list of cities by calling the <code>getCityList</code> method from our service. We will bind the list of cities to a dropdown list in our HTML page. Since we are calling the <code>getCityList</code> method in <code>ngOnInit</code>, the dropdown list will be populated as the page loads.</li>
<li>We will check if the <code>id</code> is set then we will change the title to “Edit”, get the data for that <code>id</code> from our service, and populate the fields in our form. The value read from the database will be returned as JSON. It will have all the same properties as we declared in our <code>FormBuilder</code>, hence we use the <code>setValue</code> method to populate our form.</li>
</ol>
<p>The save method will be called when the “Save” button of our form is clicked. The <strong>add</strong> and <strong>edit</strong> operations will call the corresponding method from our service and then, upon success, redirect back to the fetch-employee component.</p>
<p>In the last one we have also defined getter functions for the control names of our form to enable client-side validation.</p>
<p>Open <code>addemployee.component.html</code> and insert the following code.</p>
<pre><code>&lt;!DOCTYPE html&gt;  &lt;html&gt;  &lt;head&gt;      &lt;meta charset="utf-8" /&gt;      &lt;title&gt;&lt;/title&gt;  &lt;/head&gt;  &lt;body&gt;        &lt;h1&gt;{{title}}&lt;/h1&gt;      &lt;h3&gt;Employee&lt;/h3&gt;      &lt;hr /&gt;      &lt;form [formGroup]="employeeForm" (ngSubmit)="save()" #formDir="ngForm" novalidate&gt;            &lt;div class="form-group row"&gt;              &lt;label class=" control-label col-md-12" for="Name"&gt;Name&lt;/label&gt;              &lt;div class="col-md-4"&gt;                  &lt;input class="form-control" type="text" formControlName="name"&gt;              &lt;/div&gt;              &lt;span class="text-danger" *ngIf="employeeForm.hasError('required', 'name') &amp;&amp; formDir.submitted"&gt;                  Name is required.              &lt;/span&gt;          &lt;/div&gt;          &lt;div class="form-group row"&gt;              &lt;label class="control-label col-md-12" for="Gender"&gt;Gender&lt;/label&gt;              &lt;div class="col-md-4"&gt;                  &lt;select class="form-control" data-val="true" formControlName="gender"&gt;                      &lt;option value=""&gt;-- Select Gender --&lt;/option&gt;                      &lt;option value="Male"&gt;Male&lt;/option&gt;                      &lt;option value="Female"&gt;Female&lt;/option&gt;                  &lt;/select&gt;              &lt;/div&gt;              &lt;span class="text-danger" *ngIf="employeeForm.hasError('required', 'gender') &amp;&amp; formDir.submitted"&gt;                  Gender is required              &lt;/span&gt;          &lt;/div&gt;          &lt;div class="form-group row"&gt;              &lt;label class="control-label col-md-12" for="Department"&gt;Department&lt;/label&gt;              &lt;div class="col-md-4"&gt;                  &lt;input class="form-control" type="text" formControlName="department"&gt;              &lt;/div&gt;              &lt;span class="text-danger" *ngIf="employeeForm.hasError('required', 'department') &amp;&amp; formDir.submitted"&gt;                  Department is required              &lt;/span&gt;          &lt;/div&gt;          &lt;div class="form-group row"&gt;              &lt;label class="control-label col-md-12" for="City"&gt;City&lt;/label&gt;              &lt;div class="col-md-4"&gt;                  &lt;select class="form-control" data-val="true" formControlName="city"&gt;                      &lt;option value=""&gt;--Select City--&lt;/option&gt;                      &lt;option *ngFor="let city of cityList"                              value={{city.cityName}}&gt;                          {{city.cityName}}                      &lt;/option&gt;                  &lt;/select&gt;              &lt;/div&gt;              &lt;span class="text-danger" *ngIf="employeeForm.hasError('required', 'city') &amp;&amp; formDir.submitted"&gt;                  City is required              &lt;/span&gt;          &lt;/div&gt;          &lt;div class="form-group"&gt;              &lt;button type="submit" class="btn btn-default"&gt;Save&lt;/button&gt;              &lt;button class="btn" (click)="cancel()"&gt;Cancel&lt;/button&gt;          &lt;/div&gt;      &lt;/form&gt;  &lt;/body&gt;  &lt;/html&gt;
</code></pre><p>Here you can observe that we have attribute <code>[formGroup]=“employeeForm”</code>, which is our defined form group name in <code>addemployee.component.ts</code>. <code>(ngSubmit)=“save()”</code> will invoke our <code>save</code> method on form submit.</p>
<p>Also, every input control has attribute <code>formControlName=“xyz”</code>. This is used to bind <code>FormControl</code> to HTML. We have also defined error messages for client-side validation checks. These will be invoked on form submission only.</p>
<p>For binding the dropdown list we are using the <code>cityList</code> property that we have populated from <code>tblCities</code>. It was populated by calling the <code>getCityList</code> method from our service, inside the <code>ngOnInit</code> method of <code>_addemployee.component.ts_</code><em>.</em></p>
<h3 id="heading-defining-the-route-and-navigation-menu-for-our-application">Defining the route and navigation menu for our Application</h3>
<p>Inside the “app” folder, open <code>app.shared.module.ts</code> and insert the following code:</p>
<pre><code><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> { EmployeeService } <span class="hljs-keyword">from</span> <span class="hljs-string">'./services/empservice.service'</span>  <span class="hljs-keyword">import</span> { CommonModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/common'</span>;  <span class="hljs-keyword">import</span> { FormsModule, ReactiveFormsModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/forms'</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> { RouterModule } <span class="hljs-keyword">from</span> <span class="hljs-string">'@angular/router'</span>;    <span class="hljs-keyword">import</span> { AppComponent } <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/app/app.component'</span>;  <span class="hljs-keyword">import</span> { NavMenuComponent } <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/navmenu/navmenu.component'</span>;  <span class="hljs-keyword">import</span> { HomeComponent } <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/home/home.component'</span>;  <span class="hljs-keyword">import</span> { FetchEmployeeComponent } <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/fetchemployee/fetchemployee.component'</span>  <span class="hljs-keyword">import</span> { createemployee } <span class="hljs-keyword">from</span> <span class="hljs-string">'./components/addemployee/AddEmployee.component'</span>    @NgModule({      <span class="hljs-attr">declarations</span>: [          AppComponent,          NavMenuComponent,          HomeComponent,          FetchEmployeeComponent,          createemployee,      ],      <span class="hljs-attr">imports</span>: [          CommonModule,          HttpModule,          FormsModule,          ReactiveFormsModule,          RouterModule.forRoot([              { <span class="hljs-attr">path</span>: <span class="hljs-string">''</span>, <span class="hljs-attr">redirectTo</span>: <span class="hljs-string">'home'</span>, <span class="hljs-attr">pathMatch</span>: <span class="hljs-string">'full'</span> },              { <span class="hljs-attr">path</span>: <span class="hljs-string">'home'</span>, <span class="hljs-attr">component</span>: HomeComponent },              { <span class="hljs-attr">path</span>: <span class="hljs-string">'fetch-employee'</span>, <span class="hljs-attr">component</span>: FetchEmployeeComponent },              { <span class="hljs-attr">path</span>: <span class="hljs-string">'register-employee'</span>, <span class="hljs-attr">component</span>: createemployee },              { <span class="hljs-attr">path</span>: <span class="hljs-string">'employee/edit/:id'</span>, <span class="hljs-attr">component</span>: createemployee },              { <span class="hljs-attr">path</span>: <span class="hljs-string">'**'</span>, <span class="hljs-attr">redirectTo</span>: <span class="hljs-string">'home'</span> }          ])      ],      <span class="hljs-attr">providers</span>: [EmployeeService]  })  <span class="hljs-keyword">export</span> <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">AppModuleShared</span> </span>{  }
</code></pre><p>Here we have also imported all our components and defined the route for our application as below:</p>
<ul>
<li>home: which will redirect to the <code>home</code> component</li>
<li>fetch-employee: to display all employee data using the <code>fetchemployee</code>component</li>
<li>register-employee: to add new employee record using the <code>createemployee</code>component</li>
<li>employee/edit/:id: to edit existing employee record using the <code>createemployee</code> component</li>
</ul>
<p>One last thing is to the define navigation menu for our application. In “/app/components/navmenu/”, open <code>navmenu.component.html</code> and insert the following code.</p>
<pre><code>&lt;div <span class="hljs-class"><span class="hljs-keyword">class</span></span>=<span class="hljs-string">'main-nav'</span>&gt;      <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'navbar navbar-inverse'</span>&gt;</span>          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'navbar-header'</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">'button'</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'navbar-toggle'</span> <span class="hljs-attr">data-toggle</span>=<span class="hljs-string">'collapse'</span> <span class="hljs-attr">data-target</span>=<span class="hljs-string">'.navbar-collapse'</span>&gt;</span>                  <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'sr-only'</span>&gt;</span>Toggle navigation<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>                  <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'icon-bar'</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">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'icon-bar'</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">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'icon-bar'</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">button</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'navbar-brand'</span> [<span class="hljs-attr">routerLink</span>]=<span class="hljs-string">"['/home']"</span>&gt;</span>ASPCoreWithAngular<span class="hljs-tag">&lt;/<span class="hljs-name">a</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">'clearfix'</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">'navbar-collapse collapse'</span>&gt;</span>              <span class="hljs-tag">&lt;<span class="hljs-name">ul</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'nav navbar-nav'</span>&gt;</span>                  <span class="hljs-tag">&lt;<span class="hljs-name">li</span> [<span class="hljs-attr">routerLinkActive</span>]=<span class="hljs-string">"['link-active']"</span>&gt;</span>                      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> [<span class="hljs-attr">routerLink</span>]=<span class="hljs-string">"['/home']"</span>&gt;</span>                          <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'glyphicon glyphicon-home'</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Home                      <span class="hljs-tag">&lt;/<span class="hljs-name">a</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">li</span> [<span class="hljs-attr">routerLinkActive</span>]=<span class="hljs-string">"['link-active']"</span>&gt;</span>                      <span class="hljs-tag">&lt;<span class="hljs-name">a</span> [<span class="hljs-attr">routerLink</span>]=<span class="hljs-string">"['/fetch-employee']"</span>&gt;</span>                          <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">class</span>=<span class="hljs-string">'glyphicon glyphicon-th-list'</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span> Fetch employee                      <span class="hljs-tag">&lt;/<span class="hljs-name">a</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">div</span>&gt;</span></span>  &lt;/div&gt;
</code></pre><p>And that’s it. We have created our first ASP.NET Core application using Angular 5 and Entity Framework core database first approach.</p>
<h3 id="heading-execution-demo">Execution Demo</h3>
<p>Press F5 to launch the application.</p>
<p>A web page will open as shown in the image below. Notice the URL showing the route for our home component. The navigation menu on the left shows the navigation link for the “Home” and “Fetch Employee” pages.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/zfm-H3j-jMEE5ZMZQCGdVCUludViC0zJS3kr" alt="Image" width="650" height="330" loading="lazy"></p>
<p>Click on “Fetch Employee” in the navigation menu. It will redirect to the <code>fetchemployee</code> component, and displays all the employee data on the page.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/hbGnwdxmGM8m9P4Va-xrwBK0BKha0dernmQP" alt="Image" width="650" height="181" loading="lazy"></p>
<p>Since we have not added any data it is empty.</p>
<p>Click on “Create New<em>”</em> to navigate to the “/register-employee<em>”</em> page. Add a new Employee record as shown in the image below. You can see that the <strong>City</strong> field is a dropdown list, containing all the city names that we inserted into <code>tblCities</code>.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/iNzUNhKhYjlpyKyc7WlYFBkyeAnNeNvB6BG9" alt="Image" width="563" height="594" loading="lazy"></p>
<p>If we miss the data in any field while creating an employee record, we will get a required field validation error message</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/SYafIcJS18WIjKzPWiqJfpEBt9ay7fmBeGoN" alt="Image" width="640" height="596" loading="lazy"></p>
<p>After inserting the data in all the fields, click on the “Save” button. The new employee record will be created, and you will be redirected to the “/fetch-employee<em>”</em> page. This page displays the records of all the employees. Here, we can also see action methods “Edit” and “Delete”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/rlUf3JpBh7uj69tQ2Fs9mWA47OKGTSiVxoSt" alt="Image" width="650" height="241" loading="lazy"></p>
<p>If we want to edit an existing employee record, click the “Edit” action link. It will open the “Edit” page as below, where we can change the employee data. Notice that we have passed the EmployeeId in the URL parameter.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/XUU6X3xe7tBTjCrTKRPLNDL7-t7Yaw3E4KFb" alt="Image" width="550" height="625" loading="lazy"></p>
<p>Here we have changed the <code>City</code> of employee Rahul from Hyderabad to Chennai. Click on “Save” to return to the “fetch-employee” page to see the updated changes as highlighted in the image below.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/fYGlFUkpv6LrwAMETcSFnSU-nFeMPNBthFTL" alt="Image" width="650" height="253" loading="lazy"></p>
<p>If we miss any fields while editing the employee records, then Edit view will also throw a required field validation error message as shown in the image below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/MejmWwE9kxJG2rwT7Abkj69Y6gcU3P6ZFrAy" alt="Image" width="646" height="567" loading="lazy"></p>
<p>Now, we will perform a “Delete” operation on an employee named Swati with Employee Id 2. Click on the “Delete” action link. This will open a JavaScript confirmation box asking for a confirmation to delete.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/4phku3XYBQRTKjYWjzhHNaglb7ZDk80nFkHD" alt="Image" width="650" height="255" loading="lazy"></p>
<p>Once we click on “OK”, the Swati who is Employee Id 2 will be removed from our record. You can see the updated list of employees as shown below.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/8iRuxCuipFk-moKUTwXdIVgHTQ9WgTt91Xga" alt="Image" width="650" height="225" loading="lazy"></p>
<h3 id="heading-other-useful-sources">Other useful sources:</h3>
<ul>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operations-asp-net-core-using-angular-5-ado-net/">CRUD Operations With ASP.NET Core Using Angular 5 and ADO.NET</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/getting-started-with-angular-5-using-visual-studio-code/">Getting Started With Angular 5 Using Visual Studio Code</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operation-asp-net-core-mvc-using-visual-studio-code-ef/">CRUD Operation With ASP.NET Core MVC Using Visual Studio Code and EF</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operation-with-asp-net-core-mvc-using-ado-net/">CRUD Operation With ASP.NET Core MVC Using ADO.NET and Visual Studio 2017</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/crud-operation-with-asp-net-core-mvc-using-visual-studio-code-and-ado-net/">CRUD Operation With ASP.NET Core MVC using Visual Studio Code and ADO.NET</a></li>
<li><a target="_blank" href="http://ankitsharmablogs.com/asp-net-core-getting-started-with-blazor/">ASP.NET Core — Getting Started With Blazor</a></li>
</ul>
<h3 id="heading-conclusion">Conclusion</h3>
<p>We have successfully created an ASP.NET Core application using Angular 5 and Entity Framework core database first approach with the help of Visual Studio 2017 and SQL Server 2012. We have used Angular forms to get data from the user and also bind the dropdown list to the database table using Entity framework.</p>
<p>You can check out my other articles on ASP .NET Core <a target="_blank" href="http://ankitsharmablogs.com/category/asp-net-core/">here</a>.</p>
<p>Originally published at <a target="_blank" href="https://ankitsharmablogs.com/">https://ankitsharmablogs.com/</a></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
