<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Vannila - Medium]]></title>
        <description><![CDATA[Game Reviews, Web development tips, Virtual Reality, Augmented Reality, Blockchain, Mobile development - Medium]]></description>
        <link>https://medium.com/vannila?source=rss----51a326726950---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Vannila - Medium</title>
            <link>https://medium.com/vannila?source=rss----51a326726950---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 23:57:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/vannila" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[0–100 in Angular: Part 6]]></title>
            <link>https://medium.com/vannila/0-100-in-angular-part-6-30240d9f2a1a?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/30240d9f2a1a</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[resolver]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Valentine Oragbakosi]]></dc:creator>
            <pubDate>Fri, 01 Nov 2019 14:00:54 GMT</pubDate>
            <atom:updated>2019-11-01T14:00:54.647Z</atom:updated>
            <content:encoded><![CDATA[<p>In our last part of this series, we learned some beneficial things in Angular which include: Making Calls, feature modules, etc. See article <a href="https://medium.com/vannila/0-100-in-angular-part-5-4bc0a396a796">here</a>.</p><p>In today’s series, we would be diving into resolvers. If you recall vividly, you would remember that sometimes Angular routes faster than we can get data from our server thus giving us an error saying data is undefined. There is excellent news, Angular has a way to solve that problem and it uses resolvers.</p><p><strong>Resolvers</strong>: Resolvers are a way to suspend the component from loading until the necessary data is sent over to the client. It makes use of the Angular activated route.</p><p>Let’s see how it works</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2fI4HJcCI0F0n9IGWdKYw.png" /></figure><p>Unfortunately, Angular doesn’t generate the resolver file for us, we would have to do that manually.</p><p>From our previous series code base, create a <strong><em>data.ressolvers.ts</em></strong> file the <strong><em>src/app/user</em></strong> directory and add the following piece of code there:</p><pre>import { Injectable } from &#39;@angular/core&#39;;</pre><pre>import { empty} from &#39;rxjs&#39;</pre><pre>import { Resolve } from &#39;@angular/router&#39;;</pre><pre>import { catchError } from &#39;rxjs/operators&#39;;</pre><pre>import { ActivatedRouteSnapshot } from &#39;@angular/router&#39;;</pre><pre>import {UserService} from &#39;./user.service&#39;<br></pre><pre>@Injectable()</pre><pre>export class GetUsers implements Resolve&lt;any&gt; {</pre><pre>constructor(private data:UserService) {}</pre><pre>resolve(){</pre><pre>return this.data.getUser().pipe(catchError((err)=&gt;{</pre><pre>return empty();</pre><pre>}))</pre><pre>}}</pre><p>This simply creates a new class GetUsers that implements Resolve. Notice we also import UserService and returned the value we get from it. If there is an error, it would not return any component. Next step, we have to tell our module that this resolver exists.</p><p>Import the resolver class in the module and add it to your providers.</p><pre>import {GetUsers} from &#39;./data.resolvers&#39;</pre><pre>providers: [GetUsers]</pre><p>Finally, we add it to our routing to make sure the conditions of the resolvers are met before routing takes place. Import it to your user routing file and modify the route where you get the list of users as such:</p><pre>import {GetUsers} from &#39;./data.resolvers&#39;</pre><pre>{</pre><pre>path:&#39;user&#39;,</pre><pre>component:UserComponent,</pre><pre>resolve:{userInfo:GetUsers}</pre><pre>}</pre><p>This would resolve the list of users in this route with the snapshot userInfo. Let’s now see how we retrieve this data in our component.</p><p>In our user component where we got the list of all the users, go ahead and add the following piece of code:</p><pre>import { ActivatedRoute } from &#39;@angular/router&#39;;</pre><pre>constructor(private router:ActivatedRoute) { }<br>list:any</pre><pre>ngOnInit() {</pre><pre>this.list=this.router.snapshot.data[&#39;userInfo&#39;]</pre><pre>}</pre><p>Notice here that we didn’t have to subscribe to our service on init, we just get the data from the activated route snapshot.</p><p>Let’s now implement resolvers for getting user by id.</p><p>As before go to your resolver file and add the following piece of code:</p><pre>@Injectable()</pre><pre>export class GetUserId implements Resolve&lt;any&gt; {</pre><pre>constructor(private data:UserService) {}</pre><pre>resolve(route: ActivatedRouteSnapshot){</pre><pre>return this.data.getProfile(route.paramMap.get(&#39;id&#39;)).pipe(catchError((err)=&gt;{</pre><pre>return empty();</pre><pre>}))</pre><pre>}</pre><pre>}</pre><p>Notice this is slightly different from the resolver class earlier because in this case, we have to use the id param from the route to make an API call. So we get the id using <strong>route.paramMap.get(‘id’)</strong> and pass it into the method.</p><p>Go ahead and update your module file and profile routing and profile component following the above example.</p><p>If all goes correctly, you would notice that you no longer the undefined error when you click the user profile.</p><p>And that’s how resolvers work in Angular folks.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30240d9f2a1a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/0-100-in-angular-part-6-30240d9f2a1a">0–100 in Angular: Part 6</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Useful Hacks in Call of Duty mobile]]></title>
            <link>https://medium.com/vannila/useful-hacks-in-call-of-duty-mobile-dc78b59338a6?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/dc78b59338a6</guid>
            <category><![CDATA[call-of-duty-mobile]]></category>
            <category><![CDATA[gaming]]></category>
            <dc:creator><![CDATA[David Asamonye]]></dc:creator>
            <pubDate>Thu, 31 Oct 2019 11:43:43 GMT</pubDate>
            <atom:updated>2019-10-31T11:45:05.534Z</atom:updated>
            <content:encoded><![CDATA[<h3>Useful Hacks in Call of Duty Mobile</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phD7oasaqe2Cwh2ZhxlgiA.jpeg" /></figure><p>Call of Duty mobile is only a month old and yet, it is already one of the most popular mobile games, this is largely due to the fact that Call of Duty mobile is worth the hype, I mean, it has console-like graphics, fantastic gameplay and a good number of fun game modes although, you only have multiplayer and battle royale right now, with a campaign mode probably coming soon as seen on the home screen. If you are just getting into the game, then this guide would help you become better at the game so you can be a valuable asset to your team members.</p><h4>Auto firing &amp; Aim Assist</h4><p>This is a very convenient and effective method for shooting at your opponents especially if you use your phone’s screen as your controller, so instead of your aim at your opponent and then press the fire button, you can simply set your character to fire whenever an opponent is within range, not only is this method quicker but it also helps you become more effective with your shots, since all you have to worry about is your aim.</p><p>To switch to autofire, jump into settings &gt; controls, then in both MP and BR mode (NB: MP stands for MultiPlayer and BR stands for Battle Royale), then tap on simple mode, you can also customize other actions for convenience and effectiveness by tapping on the Custom Layout button below, personally, I like to have my “melee” and “grenade throw” on the left-hand side of the screen, so I can use my right-hand to aim and then take action with my left hand, it makes me more effective.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ggRnNAWTNeAKvzMhtybVyw.jpeg" /></figure><p>In default cases, aim assist is set to ON but just in case, you can head to settings &gt; basic, then toggle the aim assist switch ON.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sJZL0_qdlIuAAAky9jwTCg.jpeg" /></figure><h4>Always Sprint</h4><p>Another useful trick is to set your character on always sprint and quick run from prone, with this, you don’t have to double-tap or drag on the virtual joystick to get your character to run, This is useful for escaping from your opponents when faced with heavy fire and it will also help you to quickly chase down opponents while attacking.</p><p>To activate, go to settings &gt; basic, toggle on Quick Run(From Prone) and also Always Sprint.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CtrYDvslRi33wXgabvjMPg.jpeg" /></figure><h4>Weapon Acquisition &amp; Mastery</h4><p>As you advance levels in the game, the more opportunity you have to unlock new weapons and upgrade your current weapons, also, you can purchase weapons and loadout crates from the store by clicking on the store button on the bottom left of the screen. Another way you can unlock new weapons is by winning the Gun Game mode which you can find among the featured modes in Multiplayer. Gun Game is a mode where after each kill, your weapon switches automatically, then you must perform a melee attack on your final kill.</p><p>Acquiring new weapons is not the full story, you must be strategic in how you use any weapon, I would even recommend you have a loadout you study and understand properly, it will help you master your weapons and become more strategic in your approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KnUmvAxEvXtS59IqWMTXeQ.jpeg" /></figure><p>For example, if you prefer to use a Sniper as your primary weapon, then you should always keep a distance from your opponents, one way you can do this is by staying in tall buildings or high places, always try to aim at and kill opponents when you are far away from them. Also, ensure your melee button is always within reach for close combat.</p><p>If you use a machine gun as your primary weapon ( This happens to be me), then you know you have an advantage because a machine gun can fire up to 100 rounds before reloading, this gives you an edge when exchanging fire with several opponents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Z1EDQ03UrZCmub3RAk3LQ.jpeg" /></figure><p>Also, some persons prefer to use a shotgun as their primary weapon, while this is very effective in close-range combat, as you only have to fire at an opponent once or twice to eliminate them, it has a very short range, meaning you have to get close to your opponents if you want your bullets to be of any effect.</p><p>The fact is, no weapon is superior to the other, each weapon has its advantage and its drawback, the most important thing is, you have to master your weapon and use it in the most effective way</p><h3>Conclusion</h3><p>Call of Duty mobile is a fun game but as with everything in life, you need to spend some quality time with it if you want to become really good at it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc78b59338a6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/useful-hacks-in-call-of-duty-mobile-dc78b59338a6">Useful Hacks in Call of Duty mobile</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Virtual Reality and Augmented Reality — Different or Similar?]]></title>
            <link>https://medium.com/vannila/virtual-reality-and-augmented-reality-different-or-similar-ec1423cd824d?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/ec1423cd824d</guid>
            <category><![CDATA[virtual-reality]]></category>
            <category><![CDATA[augmented-reality]]></category>
            <dc:creator><![CDATA[David Asamonye]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 08:07:31 GMT</pubDate>
            <atom:updated>2019-10-22T08:07:30.964Z</atom:updated>
            <content:encoded><![CDATA[<h3>Virtual Reality and Augmented Reality — Different or Similar?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*VpBZIG6ZnZvXeq3r_ZqwUw.jpeg" /></figure><p>The more I delve into Virtual and Augmented Reality, the more excited I am about these fields of study and the more I become more dedicated to exploring them both. Today, we will not go over how to get started with building Virtual Reality or Augmented Reality, we will cover that in another article, this is more like an introductory article to the two concepts.</p><p>For the sake of newbies, I would go over defining the basics of both Virtual and Augmented Reality.</p><p><strong>What is Virtual Reality?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/1*u-xB_93erXaxUdBCiVBv4w.jpeg" /></figure><p><strong>Virtual Reality is a simulation of a virtual world</strong>, sort of like an alternate universe, where the user sees and hears an experience that is created by man. It gives you a feeling of immersion into the game or movie that is being experienced.</p><p><strong>What is Augmented Reality?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*p0kQWXyw8V61Ha6OnIMxkg.jpeg" /></figure><p>while Virtual Reality is a simulated virtual world, <strong>Augmented Reality is the superimposition of virtual objects on the real world</strong>, In Augmented Reality, you are still conscious of the real world around but with the insertion of virtual objects, which through several techniques, look and act as though they are present in the real world.</p><p>To the beginner, both may be hard to tell apart, most especially if one has not had any experience of both but the more you learn about them, the further apart they grow in your mind.</p><p>The truth is, they share some similarities but from my experience, they are a lot more different than they are similar both in terms of experiencing them and most especially the techniques and technologies that are used to build them.</p><p><strong>Similarities</strong></p><p>The major similarity between VR and AR is the fact that both have to deal with virtual objects meaning that whether you are working on a VR project or an AR project, you would either have to create your own “Game” objects or import already existing objects into your project and for the most part, you may have to do so using a Game engine such as Unity or Unreal Engine or build your Objects from scratch.</p><p><strong>Differences &amp; Unique Challenges</strong></p><p>The differences of both lie in the way they have to be presented to the end-user, VR is basically a simulation, meaning that as a creator, you must be able to give your user the feeling that the experience is real, for this to happen, the VR device should be powerful enough to deliver consistent high <strong>framerates</strong>, as any drop in framerates would break the immersion.</p><p>Virtual Reality is all about convincing a user that the virtual world he is experiencing at the moment is no different from the real world, right now, there are some limitations in achieving this goal namely;</p><ul><li>The two lenses used for each eye magnifies the screen which makes the view in most VR devices <strong>pixelated.</strong></li><li>For there to be an illusion of reality, all the human senses must perceive something similar, imagine you are feeling cold while your eyes can see fire all around, this makes it difficult to be convinced that the experience is real. Another example is you enjoying a fast-moving VR experience while you are sitting on the couch in your living room, as a matter of fact, this causes a very popular problem with VR today called Motion sickness, this just basically means that what the body sees is not in tandem with its sense of movement.</li></ul><p>There are still other limitations to achieving the illusion of reality in VR but I believe these are the major challenges. It is important to note that regardless of these challenges, VR is still a very enjoyable experience and if you haven’t tried it, I urge you to give it a try, you will not regret it.</p><p>For Augmented Reality, the user doesn’t have to be convinced that the experience is real, the main challenge in AR is for the user to feel as though the virtual objects are part of the real world. What this means is that the virtual objects must properly overlap the real world, that is, if you added a virtual dog to stand on the ground, the dog must be seen as standing on the ground, if the dog is perceived to be floating, the experience would appear unreal.</p><p>Another challenge has to do with lighting, imagine being in a poorly lit room and then you introduce a virtual object into the environment and the virtual object looks really bright, it will appear unreal also, the virtual object has to be lighted according to the room lighting both in terms of amount and the source direction.</p><p>One other challenge with AR is something called Occlusion, I will explain with an example. Suppose you place a virtual cup on a distant table, let’s assume the cup properly overlaps and sits on the table and the lighting was correct, imagine that someone walks in between you and the table and you still get to see the cup even while there is an obstacle(the human subject), the makes the experience appear fake, I do believe it is quite challenging because it involves the AR device to be able to sense depth and arrange objects based on their proximity, also, suppose the subject in between the virtual object and the AR device is transparent, the AR device should make an exception to that.</p><p><strong>Conclusion</strong></p><p>The fields of VR and AR are really exciting areas of exploration, a lot has been achieved but a lot more still needs to be achieved. Currently, there are SDKs and other tools that try to tackle the challenges that are unique to VR or AR but they are not yet perfect. This is going to be our first article in a series based on building VR and AR experiences, our next article will be an introduction to the tools and technologies used in building both VR and AR experiences, so stay tuned for that!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ec1423cd824d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/virtual-reality-and-augmented-reality-different-or-similar-ec1423cd824d">Virtual Reality and Augmented Reality — Different or Similar?</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[0–100 in Angular: Part 5]]></title>
            <link>https://medium.com/vannila/0-100-in-angular-part-5-4bc0a396a796?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/4bc0a396a796</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Valentine Oragbakosi]]></dc:creator>
            <pubDate>Tue, 22 Oct 2019 02:10:10 GMT</pubDate>
            <atom:updated>2019-10-22T02:10:10.700Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello guys, welcome to another series on Angular. In our last series we talked about routing extensively and route guard. You can read up <a href="https://medium.com/vannila/0-100-in-angular-part-4-c5c7e5688281">here</a>. In this part, we would talk about the following concepts:</p><ol><li>Feature module</li><li>Dependency Injection</li><li>Parent and children components</li><li>API calls (in Angular)</li><li>Services</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*ZOw0vt-VsIk96mm3-RvlYQ.jpeg" /></figure><p><strong>Feature module</strong> is a way of creating more modules other than the default one given to us by Angular. It helps keep our code organized and separate different parts of our application based on their concerns</p><p><strong>Dependency Injection</strong> is simply a technique in programming where an object supplies the dependencies to another object thus allowing code to be abstracted and reused.</p><p><strong>Parent and Children component</strong> is simple having a parent component with other sub-components that we call children component.</p><p><strong>API calls</strong>. In real life, we would have our angular application communicate with an API so as to get, post, delete, put, etc data. Angular uses HttpClient which is an inbuilt feature in Angular that allows us to make AJAX calls.</p><p><strong>Services</strong> in Angular is where we mostly keep code that would be reused across different components and classes. It helps with reusable code.</p><p>In this tutorial, we would be using JSON-server as our API. It is an npm package that allows us to set up a fake API in a couple of seconds. It’s a very good tool I use a lot. To install, run the command</p><pre>npm install -g json-server</pre><p>If you are using GNU/Linux, you might want to give it root access</p><pre>sudo npm install -g json-server</pre><p>Next up, create a db.json file anywhere you please and add the following piece of JSON there:</p><pre>{<br>  &quot;users&quot;: [<br>    { &quot;id&quot;: 1, &quot;name&quot;: &quot;Chidi Nwoke&quot;, &quot;email&quot;: &quot;<a href="/service/mailto:chidi@gmail.com">chidi@gmail.com</a>&quot; },<br>    { &quot;id&quot;: 2, &quot;name&quot;: &quot;Oge Okonkwo&quot;, &quot;email&quot;: &quot;<a href="/service/mailto:oge@gmail.com">oge@gmail.com</a>&quot; },<br>    { &quot;id&quot;: 3, &quot;name&quot;: &quot;David Tayo&quot;, &quot;email&quot;: &quot;<a href="/service/mailto:tayomil@gmail.com">tayomil@gmail.com</a>&quot; }<br>  ]<br>}</pre><p>After that, go to the directory you created the db.json file and run the command</p><pre>json-server --watch db.json</pre><p>This would start a server and if all goes well, you should see the list of users in your browser if you visit <a href="http://localhost:3000/users"><strong><em>http://localhost:3000/users</em></strong></a> and the first user if you visit <a href="http://localhost:3000/users"><strong><em>http://localhost:3000/users</em></strong></a><strong><em>/1.</em></strong></p><p>Now that we have everything set up, let’s get started with our Angular application. First, we want to create our new module which we would call “user”. To do that, run the command</p><pre>ng generate module user</pre><p>This would create a new folder called user with a <strong><em>user.module.ts</em></strong> file. Let’s go ahead and inform the original <strong><em>app.module.ts</em></strong> file about its existence. First, we import it into the <strong><em>app.module.ts, </em></strong>and add it to our imports as such:</p><pre>import {UserModule} from &#39;./user/user.module&#39;;</pre><pre>imports: [</pre><pre>UserModule</pre><pre>]</pre><p>Now we are good to go. Let’s go ahead and create some new components for our new module. We would create a home component, user (for listing all the users and adding new users) component, profile (for getting a single user) component, and edit component. Run the following command</p><pre>ng g c user/home</pre><pre>ng g c user/profile</pre><pre>ng g c user/user</pre><pre>ng g c user/edit</pre><p>Now that we have the following component, let’s go ahead and create routing for them. In the <strong><em>src/app/user</em></strong> folder create a <strong><em>user-routing.module.ts</em></strong> file. Add the following code there</p><pre>import { Routes, RouterModule } from &#39;@angular/router&#39;;</pre><pre>import { HomeComponent } from &#39;./home/home.component&#39;;</pre><pre>import { UserComponent } from &#39;./user/user.component&#39;;</pre><pre>import { ProfileComponent } from &#39;./profile/profile.component&#39;;</pre><pre>import { EditComponent } from &#39;./edit/edit.component&#39;</pre><pre>const UserRoutes: Routes = [</pre><pre>{ path: &#39;user&#39;,</pre><pre>component:HomeComponent,</pre><pre>children: [</pre><pre>{</pre><pre>path:&#39;user&#39;,</pre><pre>component:UserComponent</pre><pre>},</pre><pre>{</pre><pre>path:&#39;profile/:id&#39;,</pre><pre>component:ProfileComponent</pre><pre>},</pre><pre>{</pre><pre>path:&#39;edit/:id&#39;,</pre><pre>component:EditComponent</pre><pre>}</pre><pre>]</pre><pre>}</pre><pre>];</pre><pre>export const UserRouter = RouterModule.forChild(UserRoutes);</pre><p>Now let’s inform our <strong><em>user.module.ts</em></strong> file of this new route we created. To do that, we import the user router class as such:</p><pre>import {UserRouter} from &#39;./user-routing.module&#39;;</pre><pre>imports: [</pre><pre>UserRouter</pre><pre>]</pre><p>To make everything work, Let’s add our router outlet in our parent component which in this case is the home component. Open the HTML of the home component and add the following piece of code for the header and router outlet</p><pre>&lt;style&gt;</pre><pre>:host {</pre><pre>font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, Roboto, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;, &quot;Segoe UI Symbol&quot;;</pre><pre>font-size: 14px;</pre><pre>color: #333;</pre><pre>box-sizing: border-box;</pre><pre>-webkit-font-smoothing: antialiased;</pre><pre>-moz-osx-font-smoothing: grayscale;</pre><pre>}</pre><pre>.spacer {</pre><pre>flex: 1;</pre><pre>}</pre><pre>.toolbar {</pre><pre>height: 60px;</pre><pre>margin: -8px;</pre><pre>display: flex;</pre><pre>align-items: center;</pre><pre>background-color: #1976d2;</pre><pre>color: white;</pre><pre>font-weight: 600;</pre><pre>}</pre><pre>.toolbar img {</pre><pre>margin: 0 16px;</pre><pre>}</pre><pre>.toolbar #twitter-logo {</pre><pre>height: 40px;</pre><pre>margin: 0 16px;</pre><pre>}</pre><pre>.toolbar #twitter-logo:hover {</pre><pre>opacity: 0.8;</pre><pre>}</pre><pre>.class2{</pre><pre>color:black;</pre><pre>}</pre><pre>@media screen and (max-width: 575px) {</pre><pre>svg#rocket-smoke {</pre><pre>display: none;</pre><pre>visibility: hidden;</pre><pre>}</pre><pre>}</pre><pre>&lt;/style&gt;</pre><pre>&lt;!-- Toolbar --&gt;</pre><pre>&lt;div class=&quot;toolbar&quot; role=&quot;banner&quot;&gt;</pre><pre>&lt;img</pre><pre>width=&quot;40&quot;</pre><pre>alt=&quot;Angular Logo&quot;</pre><pre>src=&quot;data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==&quot;</pre><pre>/&gt;</pre><pre>&lt;span&gt;Welcome&lt;/span&gt;</pre><pre>&lt;div class=&quot;spacer&quot;&gt;&lt;/div&gt;</pre><pre>&lt;a aria-label=&quot;Angular on twitter&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot; href=&quot;https://twitter.com/angular&quot; title=&quot;Twitter&quot;&gt;</pre><pre>&lt;svg id=&quot;twitter-logo&quot; height=&quot;24&quot; data-name=&quot;Logo — FIXED&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot; viewBox=&quot;0 0 400 400&quot;&gt;</pre><pre>&lt;defs&gt;</pre><pre>&lt;style&gt;</pre><pre>.cls-1 {</pre><pre>fill: none;</pre><pre>}</pre><pre>.cls-2 {</pre><pre>fill: #ffffff;</pre><pre>}</pre><pre>&lt;/style&gt;</pre><pre>&lt;/defs&gt;</pre><pre>&lt;rect class=&quot;cls-1&quot; width=&quot;400&quot; height=&quot;400&quot; /&gt;</pre><pre>&lt;path class=&quot;cls-2&quot; d=&quot;M153.62,301.59c94.34,0,145.94-78.16,145.94-145.94,0-2.22,0-4.43-.15-6.63A104.36,104.36,0,0,0,325,122.47a102.38,102.38,0,0,1-29.46,8.07,51.47,51.47,0,0,0,22.55-28.37,102.79,102.79,0,0,1-32.57,12.45,51.34,51.34,0,0,0-87.41,46.78A145.62,145.62,0,0,1,92.4,107.81a51.33,51.33,0,0,0,15.88,68.47A50.91,50.91,0,0,1,85,169.86c0,.21,0,.43,0,.65a51.31,51.31,0,0,0,41.15,50.28,51.21,51.21,0,0,1-23.16.88,51.35,51.35,0,0,0,47.92,35.62,102.92,102.92,0,0,1-63.7,22A104.41,104.41,0,0,1,75,278.55a145.21,145.21,0,0,0,78.62,23&quot;</pre><pre>/&gt;</pre><pre>&lt;/svg&gt;</pre><pre>&lt;/a&gt;</pre><pre>&lt;/div&gt;</pre><pre>&lt;div class=&quot;content&quot; role=&quot;main&quot;&gt;</pre><pre>&lt;router-outlet&gt;&lt;/router-outlet&gt;</pre><p>The <strong>router-outlet</strong> is where the child component would be rendered when a new child route is hit. Now hit <strong><em>localhost: 4200/user, localhost:4200/user/user, localhost:4200/user/profile/1 </em></strong>and see how our children parent component relates.</p><p>Let’s generate a new user service so as to communicate with our fake API. Run the command</p><pre>ng g service user/user</pre><p>Now that our service is generated, let’s go ahead and import HTTP client module into our user module as such:</p><pre>import { HttpClientModule } from &#39;@angular/common/http&#39;;</pre><pre>import:[</pre><pre>HttpClientModule<br>]</pre><p>The next step is to import HttpClient into our <strong><em>user.service.ts</em></strong> file and add it to our constructor as such</p><pre>import { HttpClient } from &#39;@angular/common/http&#39;;</pre><pre>constructor(private http:HttpClient) { }</pre><p>Having done that, let’s create all the methods we would need which include: getting all users, get user by id, edit user, add user, and delete a user. Thankfully JSON-server has all these features</p><p>The method to get all users:</p><pre>getUser(){</pre><pre>return this.http.get(&#39;http://localhost:3000/users&#39;)</pre><pre>}</pre><p>As you can see, the HttpClient makes a get request to our endpoint and returns the value it gets from it.</p><p>To get user by id:</p><pre>getProfile(id){</pre><pre>return this.http.get(&#39;http://localhost:3000/users/&#39;+id)</pre><pre>}</pre><p>This takes in a parameter that is the id of the user and appends it to the endpoint to get the user details.</p><p>To add a new user:</p><pre>addUser(data){</pre><pre>return this.http.post(&#39;http://localhost:3000/users&#39;, data)</pre><pre>}</pre><p>We pass in a parameter called data to this function. This data is the value of the form we want to add</p><p>To edit user:</p><pre>editUser(data, id){</pre><pre>return this.http.put(&#39;http://localhost:3000/users/&#39;+id, data)</pre><pre>}</pre><p>This method takes in two parameters which are the data we want to update and the id of the user we want to update their details.</p><p>To delete user:</p><pre>deleteUser(id){</pre><pre>return this.http.delete(&#39;http://localhost:3000/users/&#39;+id)</pre><pre>}</pre><p>This method takes in the id of the user we want to delete. Now let’s make these methods work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*S-m_Vglp09l2sa1aO9bDDA.jpeg" /></figure><p>Let’s first of us import the user service into our <strong><em>src/app/user/user/user.component.ts</em></strong> file and use the get user method. This is a clear example of dependency injection in action</p><pre>import {UserService} from &#39;../user.service&#39;</pre><pre>//add it to your constructor</pre><pre>list:any</pre><pre>ngOnInit() {</pre><pre>this.data.getUser().subscribe(value=&gt;{</pre><pre>this.list=value</pre><pre>})</pre><pre>}</pre><p>We added the code on the initialization of the component because we want to get the list once the component is initialized. The data.getUser() is what references the getUser() method in our service. After doing that, we have to subscribe to the method and take the value returned by the method. Imagine subscribe in this cast like promises. To view the list in our HTML, add the following piece of code to the HTML file</p><pre>&lt;ul *ngFor=&quot;let a of list&quot;&gt;</pre><pre>&lt;li &gt;{{a.name}}&lt;/li&gt;</pre><pre>&lt;li&gt;{{a.email}}&lt;/li&gt;</pre><pre>&lt;/ul&gt;</pre><p>Voila, our code works :) let&#39;s move on.</p><p>Now we would add a link that links to a user profile. Let’s modify our HTML to accommodate this</p><pre>&lt;ul *ngFor=&quot;let a of list&quot;&gt;</pre><pre>&lt;li &gt;{{a.name}}&lt;/li&gt;</pre><pre>&lt;li&gt;{{a.email}}&lt;/li&gt;</pre><pre>&lt;a routerLink=&quot;/user/profile/{{a.id}}&quot;&gt;profile&lt;/a&gt;</pre><pre>&lt;/ul&gt;</pre><p>Now let’s add the user data from our API to our profile page. Import the user service as described above and add it to your constructor. In this new component, we would also need to import activated Route to get the parameter from the current route so as to make a query with it (recall that our profile component has a /: id as an identifier for unique users).</p><p>Your profile component should have a constructor that looks like this:</p><pre>parameter:string</pre><pre>constructor(private data:UserService, private router:ActivatedRoute) {</pre><pre>this.router.params.subscribe(params =&gt; this.parameter = params.id)</pre><pre>}</pre><p>The router.params.subscribe is what get’s the value of the current param, whether 1, 2 or 3. Add the following on init:</p><pre>this.data.getProfile(this.parameter).subscribe(value=&gt;{</pre><pre>this.user=value</pre><pre>})</pre><pre>}</pre><p>In your profile view, we can now go ahead and add the following to view the details:</p><pre>&lt;h3&gt;</pre><pre>{{user.name}}</pre><pre>&lt;/h3&gt;</pre><pre>&lt;p&gt;{{user.email}}&lt;/p&gt;</pre><p>Let’s go back to our user component and add a form field to add new users. Import the form module and reactive form module to your user module and of course, add them to the imports.</p><p>Set up your form as we covered <a href="https://medium.com/vannila/0-100-in-angular-part-2-c2ac5cde9364">this</a> series.</p><p>Your submit method should look like this</p><pre>submit(){</pre><pre>var userValue=this.newUser.value;</pre><pre>this.data.addUser(userValue).subscribe(value=&gt;{</pre><pre>this.list.push(value);</pre><pre>})</pre><pre>}</pre><p>So that on successful submission, the list.push() method appends the item to our list without reloading the page.</p><p>Your form should also look like</p><pre>&lt;form [formGroup]=&quot;newUser&quot; (ngSubmit)=&quot;submit()&quot;&gt;</pre><pre>&lt;input placeholder=&quot;name&quot; type=&quot;text&quot; formControlName=&quot;name&quot;&gt;</pre><pre>&lt;input placeholder=&quot;email&quot; type=&quot;email&quot; formControlName=&quot;email&quot;&gt;</pre><pre>&lt;button [disabled]=&quot;newUser.invalid&quot;&gt;submit&lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><p>So if yours work well, whenever you add a new name, it appends to your db.json file. Greate right? Now let’s make it possible to delete names from the list. Let’s modify our list in the user component HTML file once again to this.</p><pre>&lt;ul *ngFor=&quot;let a of list&quot;&gt;</pre><pre>&lt;li &gt;{{a.name}}&lt;/li&gt;</pre><pre>&lt;li&gt;{{a.email}}&lt;/li&gt;</pre><pre>&lt;a routerLink=&quot;/user/profile/{{a.id}}&quot;&gt;profile&lt;/a&gt;</pre><pre>&lt;button (click)=&quot;delete(a)&quot;&gt;delete&lt;/button&gt;</pre><pre>&lt;/ul&gt;</pre><p>Of course, be sure to create a delete method in your TS file that takes in one parameter. The delete method should look like this:</p><pre>delete(user){</pre><pre>this.data.deleteUser(user.id).subscribe(value=&gt;{</pre><pre>var index=this.list.indexOf(user);</pre><pre>this.list.splice(index, 1);</pre><pre>})</pre><pre>}</pre><p>This splice the object we delete clicked after the delete method is successful.</p><p>That was a whole lot to take in at once, right? Try pushing yourself and writing the edit method all by yourself.</p><p>Before I leave, you might have noticed an error on your web console that tells you that name and email is undefined but it, later on, goes to display. The reason is simply becauseAngular router is very fast, so it routes before the API call is complete. In a future series, we would solve this problem by adding resolvers to resolve the API call before the component is loaded.</p><p>Till then, have a nice day :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bc0a396a796" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/0-100-in-angular-part-5-4bc0a396a796">0–100 in Angular: Part 5</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Performing Binary Search in JavaScript and Ruby]]></title>
            <link>https://medium.com/vannila/performing-binary-search-in-javascript-and-ruby-ebdefff630ff?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/ebdefff630ff</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[David Asamonye]]></dc:creator>
            <pubDate>Sun, 13 Oct 2019 10:30:37 GMT</pubDate>
            <atom:updated>2019-10-14T09:16:50.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pcKgJKJ0vdX9fcNa89Vhmg.png" /></figure><p>Binary Search is arguably the most effective means of searching through very large data to find a target value. It does by eliminating half of the data each time it traverses through to find the target. For example, if you were to search through 1–20 to find 11, how would you do that? the first reaction would be to search linearly by counting from 1 till you find 11, you won’t notice how tasking this can be until you are searching for 1,123,000 out of 2,000,000 numbers but you can greatly simplify this process using binary search. If we are to find 11 from 1–20 using binary search, all we have to do is get the value in the middle i.e. 10 and we compare with 10 with our target value, since 11 is greater than 10, we then eliminate every value from 10 downwards, then we get the middle value once again between 10–20 i.e. 15 then compare with 11, now 11 is less than 15, so in the case, we eliminate all values from 15 upwards, we keep repeating this step until we find the target value. Again, since the dataset (1–20) is small, we may not notice how time and effort saving binary search can be until you search a very large set of data.</p><p>Binary search becomes more effective with increase in data. For instance, we would require a lot less steps while searching for 1,123,000 among 2,000,000 numbers compared to linear search than we would search for 11 among 20 numbers. Let’s run a pseudocode to see how many steps it will take us to search for 19 among 30 numbers;</p><ul><li>First, we set our default min and max values to 0 and array.length i.e. 29 respectively.</li></ul><pre>min = 0<br>max = 29</pre><ul><li>Get the average of the min and max values and set it to a variable of your choice, let’s call ours <em>search</em>. Remember to round search to the nearest whole number.</li></ul><pre>search = (0+29)/2 = 14.5 ~ 15</pre><ul><li>Compare search to the target value 19, if search = 19, then we have found our answer, if not, we can proceed. In this case, search is not equal to 19.</li></ul><pre>if search == targetValue<br>    return search</pre><ul><li>If search is less than targetValue, we set min = search + 1. Since search, 15, is less than targetValue, 19, we set our min = 15+1=16</li></ul><pre>if search &lt; targetValue<br>    min = search + 1</pre><ul><li>Next, we recalculate our search variable, i.e. (16+29)/2 = 45/2 = 22.5 ~ 23. Remember, we always round off search.</li></ul><pre>search = (16+29)/2 = 22.5 ~ 23</pre><ul><li>Compare search to target value once again, as before, if search == target value, we simply return search. In this case, search is greater than the target value.</li></ul><pre>if search == targetValue<br>    return search</pre><ul><li>If search is greater than targetValue, we set max = search -1. i.e. max = 23–1=22.</li></ul><pre>if search &gt; targetValue<br>   max = search - 1</pre><ul><li>Once again, we recalculate our search value, i.e. (16+22)/2 = 38/2 = 19.</li></ul><pre>search = (16+22)/2 = 38/2 = 19</pre><ul><li>Compare search to target value once again, as usual, if search==targetValue, we have found our answer. Here, search == target meaning, we found our answer! So we return search.</li><li>Lastly, if none of the above conditions are met, we set the function to return -1.</li></ul><p>It took us 9 steps to search for our target value among 30 numbers, if we were to count linearly, it will take about 19 steps to do the same, so now you can see how effective Binary search is.</p><p>Now, we are going to translate our pseudocode into real-life code in JavaScript and Ruby so we can better appreciate Binary search:</p><h4>Ruby implementation</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*rEB46tAdJHUtI15JoYm_YA.png" /></figure><h4>JavaScript</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*7NA4fzQZUSplt7ih-wVZ-Q.png" /></figure><h3>Conclusion</h3><p>One very important thing to note about performing a Binary search is that you slice the array in half each time you perform a search. In our code above, we made an iterative solution for solving Binary search, you could also solve the problem using recursion if you want to. The true power of binary search lies when you have millions probably billions of elements to search through, it is also a widely used method for search in Computing.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ebdefff630ff" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/performing-binary-search-in-javascript-and-ruby-ebdefff630ff">Performing Binary Search in JavaScript and Ruby</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[eFootball PES 2020 Review]]></title>
            <link>https://medium.com/vannila/efootball-pes-2020-review-b9dee75d4edd?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/b9dee75d4edd</guid>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[game-review]]></category>
            <dc:creator><![CDATA[David Asamonye]]></dc:creator>
            <pubDate>Mon, 07 Oct 2019 09:06:26 GMT</pubDate>
            <atom:updated>2019-10-07T09:06:26.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*14Sk47Fh2JXprXrBt-gECA.jpeg" /></figure><p>Football simulators are games I always look forward to towards the end of the year. I have been playing both PES and FIFA for more than 10 years now and for whatever reason, I always seem to prefer PES over FIFA, I would admit, PES is far from being perfect, mainly due to its lack of licensing rights for a lot of football teams and leagues but the interesting about that is, Konami constantly strive to make fixing that as easy as possible. I am not going to be comparing FIFA to PES in this review as I feel that is more of “comparing Apple to Oranges”, they both have their strengths and flaws and their different fanbase.</p><p>eFootball PES 2020 was released almost two weeks late compared to last year’s release, PES 2019. Konami, this year, is really serious about gaining a lot of followers and getting a number percentage of the football gamers market share and as such, they made a ton of improvements to the game, ranging from the gameplay, ball physics, tactics, graphics, interface, master league, if you were an expert in an older generation of the game, even PES 2019, you may appear as a novice in PES 2020, I have had eFootball PES 2020 for a while but I am still amazed at how much I have to learn in this game.</p><h3>Gameplay</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*3Q-E8k2x66STPzn2G9I6ow.jpeg" /></figure><p>eFootball PES 2020 made a lot of changes to the way the game is played on the pitch, the ball movements this year is the most realistic I have seen in any football game, the players are now more human-like than ever, I mean you actually have to play this game like you would expect to play in real life, you cannot expect players to make unnatural moves such as giving a good cross when under pressure or always making accurate one-time passes, it is quite frustrating at first because I guess I played FIFA 19 a lot more than I played PES this year and so I am sort of used to one-time passes. As time went by, I came to appreciate just how real the game feels due to the number of errors that the players can make, I mean, passing in this game requires a good amount of brainpower if you want anything meaningful to come out of it. Dribbling requires a good amount of timing, same as defending and shooting, to be honest, the is the closest game to a real-life football game, in my opinion, I hope Konami continues to improve on this.</p><h3>Graphics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/648/1*d6QyeFCmC55zHS-4oyc98w.jpeg" /></figure><p>As usual, we cannot talk about PES without talking about amazing graphics, this is one area where PES has always excelled, each year, the graphics of the game keeps getting better and better, the player faces, shirt physics, movements, the pitch, everything looks very close to real life. I believe if you take out the player indicator above their heads, the name bar and radar below, you may actually be fooled into thinking it is a real football match till you look closely, this is mainly due to the new realistic broadcast camera angle, the slow tempo of the game and just how real the players themselves look.</p><h3>Licenses</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*pLY5JPnjq4vr2wuPpQS4Uw.jpeg" /></figure><p>Konami usually does not accurately represent big leagues and many teams mainly in Europe due to the lack of such licenses. Also, losing the exclusive rights to UEFA competitions was a very huge blow to Konami in terms of licenses, licensed UEFA competitions are always fun to play in Master League mode. This year, Konami was able to get a good number of strategic partnerships and licenses such as partnerships with Manchester United, Bayern Munich, Juventus while retaining previous partnerships such as with Barcelona, Arsenal.</p><p>In terms of licenses, Konami usually does something really interesting, they keep making it super easy to import and use correct emblems and kits for teams and leagues especially in PlayStation and Windows, so if you really care of using the correct kits, you can easily in a very short time import them into your game.</p><h3>Conclusion</h3><p>To be honest, there are only a very few things wrong with this game, if you are planning to buy eFootball PES 2020, go for it! You will not regret it at all, it is a great game all around. Whether you will be playing with friends locally, playing online or playing against the AI in Master League mode, you will never be bored as long as you are a football fan.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b9dee75d4edd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/efootball-pes-2020-review-b9dee75d4edd">eFootball PES 2020 Review</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[0–100 in Angular: Part 4]]></title>
            <link>https://medium.com/vannila/0-100-in-angular-part-4-c5c7e5688281?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/c5c7e5688281</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Valentine Oragbakosi]]></dc:creator>
            <pubDate>Sun, 06 Oct 2019 12:53:50 GMT</pubDate>
            <atom:updated>2019-10-06T12:53:50.498Z</atom:updated>
            <content:encoded><![CDATA[<p>Good day guys, in the last part of this series we dived into routing and pipes. Read more <a href="https://medium.com/vannila/0-100-in-angular-part-3-7668009516e3">here</a>. Today we would go a step further and learn the following concepts:</p><ol><li><strong>Routing with parameters</strong></li><li><strong>Redirecting</strong></li><li><strong>Route guard</strong></li></ol><p>So let’s get started here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*xWuiV_8GPfIgZd1rRrkAkQ.jpeg" /></figure><p>Routing with parameters is a concept used a lot in programming to route to a page or endpoint to get data for a particular item or group of items using a unique identifier. eg to get the profile for user 1 might require us to visit the page <a href="https://myweb.com/user/1"><strong><em>https://myweb.com/user/1</em></strong></a><strong><em> </em></strong>this would route us to the user 1 page and get his data. Notice the 1 at the end of the route, it’s the unique identifier for user 1. It can also be changed to another number to get that user identifier, meaning that it’s shouldn’t be hardcoded.</p><p>Redirecting is a very familiar concept that we all have experienced. For example, on a successful login/signup, you should be taken to another page.</p><p>Route guard is a way to protect certain routes from unauthorized users. For example, users who are not logged in should not be allowed to a particular page. So we achieve that using route guard.</p><p>Let’s start with routing with parameters:</p><p>Generate a new route called item (or anything you wish) with the command</p><pre>ng g c item</pre><p>As we specified in an earlier series, specify the route for the item component in the <strong><em>src/app/app-routing.module.ts</em></strong> as such</p><pre>{</pre><pre>path:&#39;item/:id&#39;,</pre><pre>component: ItemComponent</pre><pre>}</pre><p>You would notice that unlike the other routes, this has a ‘<strong><em>/: id</em></strong>’ in it. That <strong>id</strong> is the parameter that we pass into the URL when accessing the route, so if we navigate to the route <a href="http://localhost:4200/item/23"><strong>http://localhost:4200/item/2</strong></a> we would see item component. In this case, 2 is our parameter. Great!!!</p><p>Now, how do we get ou parameter to be used in our application? The first step is easy.</p><p>Import activated route into your item component and specify it in your constructor as such</p><pre>import { ActivatedRoute } from &#39;@angular/router&#39;;</pre><pre>//code here</pre><pre>constructor(private router:ActivatedRoute) { }</pre><p>This module would allow us to get the current route and work with it. Next, we specify a variable of type string with the name parameter and assign it to the current parameter inside our constructor as such:</p><pre>parameter:string</pre><pre>constructor(private router:ActivatedRoute) {</pre><pre>this.router.params.subscribe(params =&gt; this.parameter = params.id)</pre><pre>}</pre><p>This would subscribe to the current parameter (we would learn subscribe extensively in a later series) and assign the value of the promise to our parameters variable we created.</p><p>You can now view the current parameter in the view by adding this to our item HTML file:</p><pre>&lt;P&gt;{{parameter}}&lt;/p&gt;</pre><p>Whenever we change our parameter, we would see the value in the view. In a later series, we would see how more useful this can be.</p><h3>Redirecting</h3><p>To understand redirecting, let’s create a login component that would save a token comprised of the user name and password and save it in local storage on successful login, after that, redirect the user to the login page.</p><p>Type the command</p><pre>ng g c login</pre><p>In your terminal, specify the route for the login page as we did earlier, now navigate to your login component and create a reactive form. If you are unfamiliar with reactive forms, reference to our previous series on it <a href="https://medium.com/vannila/0-100-in-angular-part-2-c2ac5cde9364">here</a>.</p><p>The form should fields of name and password. The password field should accept a minimum of 6 characters. Your form group should look like this:</p><pre>this.LoginForm=this.fb.group({</pre><pre>name:[&#39;&#39;, Validators.required],</pre><pre>password:[&#39;&#39;, [Validators.minLength(6), Validators.required]]</pre><pre>})</pre><p>Next in your login component, import Router as such:</p><pre>import {Router} from &#39;@angular/router&#39;</pre><p>Don’t forget to define it in your constructor. This component would be used for our redirecting feature.</p><p>Create the view for the form as such:</p><pre>&lt;form (ngSubmit)=&quot;submit()&quot; [formGroup]=&quot;LoginForm&quot;&gt;</pre><pre>&lt;input type=&quot;text&quot; formControlName=&quot;name&quot; placeholder=&quot;name&quot;&gt;</pre><pre>&lt;input type=&quot;password&quot; formControlName=&quot;password&quot; placeholder=&quot;password&quot;&gt;</pre><pre>&lt;button [disabled]=&quot;LoginForm.invalid&quot;&gt;submit&lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><p>Our submit function should look like this:</p><pre>submit(){</pre><pre>var formValue=this.LoginForm.value;</pre><pre>localStorage.setItem(&#39;token&#39;, formValue)</pre><pre>this.router.navigate([&#39;&#39;])</pre><pre>}</pre><p>This piece of code just simply states that first, get the value of the login form, save it in local storage with the name token, then navigate to our landing page which we specified in our routing page in a previous series.</p><p><strong>Note</strong>: In a real-life application, we want to communicate with a real server to validate the user credentials. So if you open the local storage of your browser, you would see something saved there with the name token. Great right?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*fRb8IxCFmvi-37zHhogpcw.jpeg" /></figure><h3>Route Guard</h3><p>Angular has inbuilt features for guarding route. So now, let’s make it impossible for a user to visit the item page without having logged in.</p><p>Type in the command in your terminal to generate an auth guard with the name <strong>auth</strong></p><pre>ng g guard auth</pre><p>If you are using the latest version of angular CLI, you would be prompted on what interface you want to implement. Go ahead and choose <strong>CanActivate. </strong>Next, we generate a service (service would also be explained in details in the future series) with the name <strong>tutorial</strong> with the command in your terminal</p><pre>ng g service tutorial</pre><p>Add the following piece of code in the <strong><em>src/app/tutorial.service.ts</em></strong> file:</p><pre>loggedIn(){</pre><pre>return !!localStorage.getItem(&#39;token&#39;)</pre><pre>}</pre><p>This would return true or false if the token is found in local storage</p><p>next in the <strong><em>auth.guard.ts</em></strong> file, clear everything there and add this piece of code</p><pre>import { Injectable } from &#39;@angular/core&#39;;</pre><pre>import { CanActivate} from &#39;@angular/router&#39;;</pre><pre>import { Router } from &#39;@angular/router&#39;;</pre><pre>import { TutorialService} from &#39;./tutorial.service&#39;;</pre><pre>@Injectable({</pre><pre>providedIn: &#39;root&#39;</pre><pre>})</pre><pre>export class AuthGuard implements CanActivate {</pre><pre>constructor(private data:TutorialService, private router:Router){}</pre><pre>canActivate():boolean{</pre><pre>if(this.data.loggedIn()){</pre><pre>return true</pre><pre>}else{</pre><pre>this.router.navigate([&#39;login&#39;])</pre><pre>return false</pre><pre>}</pre><pre>}</pre><pre>}</pre><p>This tells the app to route to the login page if the loggedin function in the service returns false. Now, let’s make it work. First, import it into your <strong><em>app.module.ts </em></strong>and add it to your providers</p><pre>import {AuthGuard} from &#39;./auth.guard&#39;</pre><pre>providers: [AuthGuard]</pre><p>Next, import it into your app-routing.module.ts file the way we imported it to our app module file and update your item routing to look like this:</p><pre>{</pre><pre>path:&#39;item/:id&#39;,</pre><pre>component: ItemComponent,</pre><pre>canActivate:[AuthGuard]</pre><pre>}</pre><p>This would specify the rules we declared in our auth guard for the item component. So if we go-ahead to the local storage and clear the token, we would be unable to access the item page, we would be redirected to the login page.</p><p>Thanks for reading, see you later.</p><h3>BYE!!!</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5c7e5688281" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/0-100-in-angular-part-4-c5c7e5688281">0–100 in Angular: Part 4</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[0–100 in Angular: Part 3]]></title>
            <link>https://medium.com/vannila/0-100-in-angular-part-3-7668009516e3?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/7668009516e3</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Valentine Oragbakosi]]></dc:creator>
            <pubDate>Tue, 01 Oct 2019 11:36:10 GMT</pubDate>
            <atom:updated>2019-10-01T11:36:10.648Z</atom:updated>
            <content:encoded><![CDATA[<p>In our last part of the series, we talked about Angular life cycle hook, reactive forms, single data binding, etc. You can check that all <a href="https://medium.com/vannila/0-100-in-angular-part-2-c2ac5cde9364">here</a>. In this part, we would be learning other concepts in Angular that make building Single Page Applications (SPA) easier.</p><p>Concepts we would learn include:</p><ol><li>Routing</li><li>Reusable components</li><li>Pipes</li><li>Custome pipes</li></ol><p>Let’s take a minute to explain these terms and what they mean.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/707/1*gvPAXMA_Yt1d_hFzulB0ag.jpeg" /></figure><p><strong>Routing</strong>: Routing is simply a way of rendering new components when a user clicks of a link or manually visit the link that leads to a component. The logic of this is done in the <strong><em>src/app/app-routing.module.ts. </em></strong>Angular makes this super easy to set up, and we would see how in a jiffy.</p><p><strong>Reusable components</strong>: This is another feature of Angular that makes it super cool to use. We can reuse components in another component, thus not needing to repeat ourselves. For example, you can have a header component and want to use it among so many other components. Instead of rewriting the headers every single time, we just use the header selector. We would also see how to use this.</p><p><strong>Pipes</strong>: This is how we format text, numbers, dates, etc .using some inbuilt rules in Angular.</p><p><strong>Custom pipes</strong>: This is a way of designing your pipes and giving it a set of rules that you decide. Talk about being your boss.</p><p>Let the coding begin!!!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*SIGTMCjJvR5TQZxpA1PmTA.png" /></figure><p>To get started, let’s generate 2 new components in addition to our home component. We would call it header component and about component. So in your terminal, run the following command</p><pre>ng g c header</pre><p>To generate the header component, and</p><pre>ng g c about</pre><p>To generate the about component.</p><p>Next, we import them into our <strong><em>app-routing.module.ts</em></strong> file so that we could use them for our routing as such:</p><pre>import { HeaderComponent } from &#39;./header/header.component&#39;;</pre><pre>import { AboutComponent } from &#39;./about/about.component&#39;;</pre><p>This simple line would make these components accessible to our routing. Now let’s create the route URL for these different components.</p><p>Remember where we specified our home component to be the base route, add the following piece of code to that array of objects</p><pre>{</pre><pre>path:&#39;header&#39;,</pre><pre>component:HeaderComponent</pre><pre>},</pre><pre>{</pre><pre>path:&#39;about&#39;,</pre><pre>component:AboutComponent</pre><pre>}</pre><p>If all works out well, we should see the message ‘header works!’ when we visit <strong><em>localhost:4200/header</em></strong> and ‘about works!’ when we visit <strong><em>localhost:4200/about</em></strong>. But we don’t expect the user to manually change these routes from the browser when he visits our site, do we? So let’s add links so the header and make the header link accessible to our home component and about component.</p><p>To add links in angular, we don’t use the conventional <strong>href </strong>unless we are linking to an external site. To link to a different component, we use <strong>routerLink</strong> instead.</p><p>In your <strong><em>header.component.html</em></strong> file add the following piece of code</p><pre>&lt;ul style=&quot;text-decoration: none&quot;&gt;</pre><pre>&lt;li&gt;&lt;a routerLink=&quot;&quot;&gt;home&lt;/a&gt;&lt;/li&gt;</pre><pre>&lt;li&gt;&lt;a routerLink=&quot;/about&quot;&gt;about&lt;/a&gt;&lt;/li&gt;</pre><pre>&lt;/ul&gt;</pre><p>The <strong>routerLink</strong> we specified would create a link to the component as specified in the <strong><em>app-routing.module.ts</em></strong> file.</p><p>Let’s now make sure that this header file is accessible in our <strong><em>home.component.html</em></strong> file and our <strong><em>about.component.html</em></strong> files. To do this is relatively simple. Just go to your <strong><em>header.component.ts</em></strong> file and you would see a selector that has the name <strong>app-header</strong>. Copy it and input it into an HTML tag, then add it to your <strong><em>home.component.html </em></strong>and <strong><em>about.component.html </em></strong>files as such:</p><pre>&lt;app-header&gt;&lt;/app-header&gt;</pre><p>We have successfully added routing and reused the header component. Now let’s see how pipes work</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*vLMktSUXu_uzJcp6QXmLRQ.jpeg" /></figure><h4>PIPES</h4><p>Let’s say in your typescript, we have a string called name that says “angular is good” and we want to display this text in our HTML as lower case, upper case, or truncate it, pipes makes this super easy as such</p><pre>&lt;h3&gt;{{name| uppercase}}&lt;/h3&gt;</pre><pre>&lt;h3&gt;{{name| lowercase}}&lt;/h3&gt;</pre><pre>&lt;h3&gt;{{name| slice:0:6}}&lt;/h3&gt;</pre><p>The first one turns the string to a lower case, the second makes it upper case, while the third splice the string from the first to the sixth index. Pretty sweet right? It also works with currency, numbers, dates, arrays, etc. Let’s another example of formating date</p><p>Say we have the current date-time in your TS file, we can use pipe to show the current date or just the time, we can use pipe to format this date as such:</p><pre>&lt;h3&gt;{{today| date:&#39;d/M/y&#39;}}&lt;/h3&gt;</pre><pre>&lt;h3&gt;{{today| date:&#39;shortTime&#39;}}&lt;/h3&gt;</pre><pre>&lt;h3&gt;{{today|date:&#39;longTime&#39;}}&lt;/h3&gt;</pre><p>Our output should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*7HLD9ykCmekT4-trZjns3Q.png" /></figure><p>You can read more about the Angular pipe <a href="https://angular.io/guide/pipes">here</a>.</p><p>Now let’s create a custom pipe to get the square of numbers.</p><p>Create a file called <strong><em>sqr.pipe.ts</em></strong> in <strong><em>src/app</em></strong> directory add the following piece of code there</p><pre>import { Pipe, PipeTransform } from &#39;@angular/core&#39;;</pre><pre>@Pipe({name: &#39;sqrNumber&#39;})</pre><pre>export class sqrNumber implements PipeTransform{</pre><pre>transform(value: number): number {</pre><pre>return Math.pow(value, 2)</pre><pre>}</pre><pre>}</pre><p>We first have to import the pipe and PipeTransform from angular core, next we give the pipe a name that we would use when calling it. Then we define a set of rules and what our pipe should return, in this case, the square of the number.</p><p>After creating the pipe, we import it into our <strong><em>app.module.ts</em></strong> file and add it to our declarations, so that Angular would be aware it exists.</p><pre>//coe here<br>import {sqrNumber} from &#39;./sqr.pipe&#39;</pre><pre>@NgModule({</pre><pre>declarations: [</pre><pre>sqrNumber,</pre><pre>]</pre><p>Now we are free to use our pipe as we which. Create a variable in your typescript of type number and assign it a value. Then in your HTML, use the custom pipe like this</p><pre>&lt;h3&gt;the square of {{mynum}} is {{mynum|sqrNumber}}&lt;/h3&gt;</pre><p>This would produce this result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*BzAh4j-YacwfvR8DDY-GIw.png" /></figure><p>Great!!!</p><p>We now have a good grasp of more concepts in Angular. Next time, we take a deeper dive. Have a great day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7668009516e3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/0-100-in-angular-part-3-7668009516e3">0–100 in Angular: Part 3</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[0–100 in Angular: Part 2]]></title>
            <link>https://medium.com/vannila/0-100-in-angular-part-2-c2ac5cde9364?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/c2ac5cde9364</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Valentine Oragbakosi]]></dc:creator>
            <pubDate>Sun, 29 Sep 2019 12:56:02 GMT</pubDate>
            <atom:updated>2019-09-29T12:56:02.537Z</atom:updated>
            <content:encoded><![CDATA[<p>In the first part of the series, we talked about setting up our angular environment and running it on a desirable port. In case you missed that, you can read more <a href="https://medium.com/vannila/0-100-in-angular-part-1-f2fab91ad5d6">here</a>. In this part, we would be building a simple list of staffs in a company and they email. We would use this simple application to learn the following</p><ol><li>Single data binding</li><li>Form submit</li><li>Data types</li><li>Angular common modules</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NiiP5FKUB317EmByGIBfaQ.jpeg" /><figcaption>let’s get started</figcaption></figure><p>First, let me define the following terms listed above</p><p><strong>Single Data Binding</strong>: In simple terms, this is a way to pass variables from your typescript component to your HTML component and updating the HTML DOM whenever the variable in your typescript changes.</p><p><strong>Form Submit: </strong>This is a way of taking input from the user and submitting it to a central pool (in our case we would use an array).</p><p><strong>Data Types</strong>: This is defining the data type our variable would accept eg string, Array&lt;number&gt;, object, any, etc.</p><p><strong>Angular Common modules: </strong>This is a module that contains the *ngFor, *ngIf, and *ngSwitch directive. The name of the directives are quite self-explanatory. The *ngFor is used to iterate over a collection of items, *ngIf accepts a true or false data type and shows the DOM if true but hides it if false, while *ngSwitch uses the switch case we are familiar with.</p><p>Now let’s code</p><p>Now open your <strong><em>src/app/app.component.html </em></strong>clear everything inside except</p><pre>&lt;router-outlet&gt;&lt;/router-outlet&gt;</pre><p>This router outlet is important for our routing in the future so we want to keep it.</p><p>We would also want to create a new component and make it our landing page. Angular makes that very simple for us. Just open a terminal in your project directory and type the command</p><pre>ng g c home</pre><p>This would generate a home component in your <strong><em>src/app</em></strong> folder and add it as a declaration to your <strong><em>app.module.ts</em></strong> this would let the module know that you have a new component. If you open the home folder, you would see a couple of files created. The <strong><em>home.component.css</em></strong> file is where all our CSS for the home component goes, the <strong><em>home.component.html </em></strong>contains our home component Html, the <strong><em>home.component.spec.ts </em></strong>is for testing our home component while the <strong><em>home.component.ts</em></strong> is the typescript for our home component where all our logic goes.</p><p>Now let’s make it our landing page. The first thing to do is to import the home component into your <strong><em>src/app/app-routing.module.ts </em></strong>and add it as the base path like so</p><pre>import { HomeComponent } from &#39;./home/home.component&#39;;</pre><pre>const routes: Routes = [</pre><pre>{<br>path:&#39;&#39;,<br>component:HomeComponent</pre><pre>}</pre><pre>];</pre><p>This would tell Angular that we want to load this component when we are in the base URL of our application. If all works well, you should see a message that says “home works!” on your browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*-9sHpw3WE89r7ExajOqrZQ.jpeg" /></figure><p>Now let’s start writing our employee list, shall we?</p><p>Now open your home.component.ts and declare a variable that would hold our list. Since this variable would hold a list of objects, we say</p><pre>list:Array&lt;object&gt;</pre><p>So now, Typescript knows to allow only objects in this array. After doing that, we would see very popular <strong>ngOnInt. </strong>This is Angular <strong>life cycle hook </strong>and what it does is to execute the code inside its curly braces whenever the component loads. And of course, we want to see our list when the component loads. So we add our array of objects inside of it as thus</p><pre>ngOnInit() {</pre><pre>this.list=[</pre><pre>{</pre><pre>name:&quot;Chidi Emma&quot;,</pre><pre>email:&quot;chidi43@gmail.com&quot;</pre><pre>},</pre><pre>{</pre><pre>name:&quot;Micheal Nwosu&quot;,</pre><pre>email:&quot;mike4real@yahoo.com&quot;</pre><pre>},</pre><pre>{</pre><pre>name:&quot;Bisola Nkiru&quot;,</pre><pre>email:&quot;buka4short@yahoo.com&quot;</pre><pre>},</pre><pre>]</pre><pre>}</pre><p>If all goes correctly, your <strong><em>home.component.ts </em></strong>file should look like this</p><pre>import { Component, OnInit } from &#39;@angular/core&#39;;</pre><pre>@Component({</pre><pre>selector: &#39;app-home&#39;,</pre><pre>templateUrl: &#39;./home.component.html&#39;,</pre><pre>styleUrls: [&#39;./home.component.css&#39;]</pre><pre>})</pre><pre>export class HomeComponent implements OnInit {</pre><pre>list:Array&lt;object&gt;</pre><pre>constructor() { }</pre><pre>ngOnInit() {</pre><pre>this.list=[</pre><pre>{</pre><pre>name:&quot;Chidi Emma&quot;,</pre><pre>email:&quot;chidi43@gmail.com&quot;</pre><pre>},</pre><pre>{</pre><pre>name:&quot;Micheal Nwosu&quot;,</pre><pre>email:&quot;mike4real@yahoo.com&quot;</pre><pre>},</pre><pre>{</pre><pre>name:&quot;Bisola Nkiru&quot;,</pre><pre>email:&quot;buka4short@yahoo.com&quot;</pre><pre>},</pre><pre>]</pre><pre>}</pre><pre>}</pre><p>Now let’s use our *ngFor directive to make sure we see all the list in our browser. And the easy way to do that is writing the following in our <strong><em>home.component.html.</em></strong></p><pre>&lt;div&gt;</pre><pre>&lt;ul *ngFor=&quot;let i of list&quot;&gt;</pre><pre>&lt;li&gt;</pre><pre>Name:{{i.name}}</pre><pre>Email:{{i.email}}</pre><pre>&lt;/li&gt;</pre><pre>&lt;/ul&gt;</pre><pre>&lt;/div&gt;</pre><p>If all goes well, we should see a list of names and emails on our browser. and just like that, we have our first Angular application (let’s throw a party).</p><p>Now let’s add the option of adding new names to the list via a form. And in this case, we would use Angular reactive form.</p><p>The first step is to add the form module to our <strong><em>app.module.ts </em></strong>and add it to our imports as such</p><pre>//other code here<br>import { FormsModule, ReactiveFormsModule } from &#39;@angular/forms&#39;;</pre><pre>imports:[</pre><pre>//other items here</pre><pre>FormsModule,</pre><pre>ReactiveFormsModule</pre><pre>]</pre><p>This would let angular know that we want to use this form in our component. Now that we have that out of the way, let’s go ahead and use the form in our <strong><em>home.component.ts</em></strong></p><ol><li>import the following in your <strong><em>home.component.ts</em></strong></li></ol><pre>import { FormControl, Validators, FormGroup, FormBuilder} from &#39;@angular/forms&#39;;</pre><p>2. Add the form builder in your constructor as such</p><pre>constructor(private fb:FormBuilder){}</pre><p>This would prepare the form builder object to be used in our class.</p><p>3. Create a variable called myForm that would hold our form group just as we did for list, but this would have a data type of FormGroup</p><pre>myForm:FormGroup</pre><p>4. Create the form instance on initialization and add validation</p><pre>this.myForm=this.fb.group({</pre><pre>name:[&#39;&#39;, Validators.required],</pre><pre>email:[&#39;&#39;, [Validators.email, Validators.required]]</pre><pre>})</pre><p>The empty quote tells the form to be empty on initialization and the validation on name says that name is a required field, while that on email says that email is also a required field that should be a valid email. This should be added in <strong>ngOnInt</strong></p><p>5. Let’s create the function to call when we submit the form (this should be outside ngOnint)</p><pre>submit(){</pre><pre>var formValue=this.myForm.value;</pre><pre>this.list.push(formValue)</pre><pre>}</pre><p>This takes the value from the form and append it to our array</p><p>6. Let’s make our <strong><em>app.component.html </em></strong>aware of this form and submit function. Create a form as thus:</p><pre>&lt;form (ngSubmit)=&quot;submit()&quot; [formGroup]=&quot;myForm&quot;&gt;</pre><pre>&lt;input type=&quot;text&quot; formControlName=&quot;name&quot; placeholder=&quot;name&quot;&gt;</pre><pre>&lt;input type=&quot;email&quot; formControlName=&quot;email&quot; placeholder=&quot;email&quot;&gt;</pre><pre>&lt;button [disabled]=&quot;myForm.invalid&quot;&gt;submit&lt;/button&gt;</pre><pre>&lt;/form&gt;</pre><p>There seems to be a lot happening here so let me explain. The <strong>ngSubmit</strong> is what tells the form which function to call when it wants to submit, the <strong>formGroup</strong> is what binds the Html form to the myForm form group in our typescript, the <strong>formControlName</strong> binds the form input to the names and validation we gave it in our typescript, while the <strong>disabled</strong> disables the button till the validations are met</p><p>If all works well, we should add names to the list and it would update to the DOM automatically without reloading the page. That’s the power of one-way data binding.</p><p>Since we updated our array, the data would also reflect in our list.</p><p>Now we can have a good grasp on many very important concepts in Angular. In your free time, update the code and make it able to delete names from the list. You can ask questions in the comment.</p><p>See you later</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exb5Y56Ldvbkl6rHEOkj3g.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2ac5cde9364" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/0-100-in-angular-part-2-c2ac5cde9364">0–100 in Angular: Part 2</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[0–100 in Angular: Part 1]]></title>
            <link>https://medium.com/vannila/0-100-in-angular-part-1-f2fab91ad5d6?source=rss----51a326726950---4</link>
            <guid isPermaLink="false">https://medium.com/p/f2fab91ad5d6</guid>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Valentine Oragbakosi]]></dc:creator>
            <pubDate>Sat, 28 Sep 2019 09:20:13 GMT</pubDate>
            <atom:updated>2019-09-29T09:17:08.119Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, this is a series of Angular tutorials to get you off your feet in angular and skyrocket you to the next level. In this series, we would start from the very basic to advanced concepts in Angular making it as simple as possible to understand.</p><figure><img alt="angular image" src="https://cdn-images-1.medium.com/max/1024/1*GmMtKznzJ1dS8sSzxzR3ow.png" /></figure><p>For this tutorial, we need the following things:</p><ol><li><strong>Node js</strong>: you can install it from <a href="https://nodejs.org/en/">here</a>. Please make sure you install version 10.16 and above because that’s the minimum required version</li><li><strong>NPM</strong>: This usually comes together with node js. So if you have installed node correctly, you should have this also.</li><li><strong>Angular CLI</strong> To install this, we open our command line or terminal and run the command</li></ol><pre>npm install -g @angular/cli</pre><p>If you are using GNU/Linux, you might want to give it root access so type the command</p><pre>sudo npm install -g @angular/cli</pre><p>supply your password and just like that you are a professional Angular developer. Just kidding, we still have a milestone to cross.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/213/1*0EQMrNyHVHbJJ2SD1lhDkw.gif" /></figure><p>Now that we have Angular all set up, let’s get this party started.</p><p>To create a new project, we open our terminal in the environment we wish to create the project. I’ll call my project vannila and I’ll create it in my JavaScript folder. So I’ll navigate to the JavaScript directory, open my terminal there and run the command</p><pre>ng new vannila</pre><p>This would ask you bunch of questions like if you would want routing and style sheet format you want. Well, I’ll pick yes because I want my app to have routing capabilities (I’ll explain this later) and I’ll also select CSS (though you can select any stylesheet format you are comfortable with). Then press enter and watch angular create bunch of files for you in the vannila directory it just created, after that it would install all the necessary dependencies and start your server. But what are dependencies? well, dependencies are libraries that your application is dependent on and needs it to run smoothly. Angular has a bunch of those eg @angular/core, @angular/forms, etc.</p><p>In case for some reason you angular CLI failed during installation thus not starting your server, no need to panic. We just navigate into the directory with the command</p><pre>cd vannila</pre><p>then we manually install the dependencies with the command</p><pre>npm install</pre><p>This would install all the dependencies stated in you vannila/package.json file. After that’s complete, run the command</p><pre>ng serve -o</pre><p>This command is simply telling Angular to serve your application and the -o tells it to open in the default browser.</p><p>And by default, Angular starts on port 4200 but if you wish to specify a new port you can run</p><pre>ng serve -o --port=3000</pre><p>This would start it on port 3000. Now we have our Angular set up, let’s understand what the different files/folders are.</p><p>You should have a folder structure that looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/198/1*x9k8EOhz7U3ViMSAQ25vcQ.png" /></figure><p><strong>e2e</strong>: This is where our e2e test are kept for running test</p><p><strong>node_modules: </strong>This folder contains all our dependencies</p><p><strong>src</strong>: Here we have our assets folder for keeping assets like images, CSS, javascript, etc. We also have the app folder that has our app.routing file for our routing, app.component.css for our CSS, app.component.html for the Html, app.component.ts for out typescript app.component.spec.ts for testing and app.module which groups all our related components, pipes, services, etc. This would be explained in details later with more examples. Other things to note in the src folder is the index.html and the style.css. The index.html is the entry point for our application. So if we need to add bootstrap CDN to our app, we just need to put it in the index.html and it would reflect in every other part of the application. While the style.css is the general styling, though every component has there style, the style.css would also affect every component in the application. Eg if you want every p tag to have a colour of red in the app, just specify that in your style.css</p><p>We also have a bunch of files like .gitignore which ignores files or folders when pushing to git, angular.json for our angular configuration, tsconfig.json for our typescript configuration (since Angular uses typescript), package.json to keep track of our packages, to specify start script and do other cool stuff, Readme.md file for adding a readme with markdown.</p><p>Next up, we would start building cool stuff with our Angular project.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f2fab91ad5d6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/vannila/0-100-in-angular-part-1-f2fab91ad5d6">0–100 in Angular: Part 1</a> was originally published in <a href="https://medium.com/vannila">Vannila</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>