<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Angular Material &#8211; Sibeesh Passion</title>
	<atom:link href="https://sibeeshpassion.com/tag/angular-material/feed/" rel="self" type="application/rss+xml" />
	<link>https://sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Tue, 10 Jul 2018 07:39:29 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Angular Material &#8211; Sibeesh Passion</title>
	<link>https://sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Generating Your First Components And Modules in Angular 5 App</title>
		<link>https://sibeeshpassion.com/generating-your-first-components-and-modules-in-angular-5-app/</link>
					<comments>https://sibeeshpassion.com/generating-your-first-components-and-modules-in-angular-5-app/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Thu, 16 Nov 2017 16:12:09 +0000</pubDate>
				<category><![CDATA[Angular]]></category>
		<category><![CDATA[Angular 5]]></category>
		<category><![CDATA[Angular Components]]></category>
		<category><![CDATA[Angular Material]]></category>
		<category><![CDATA[Angular Modules]]></category>
		<category><![CDATA[Creating Registration Form in Angular App]]></category>
		<category><![CDATA[Routing in Angular 5]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=12548</guid>

					<description><![CDATA[[toc] Introduction This post is a continuation of the course Developing an Angular 5 App series if you haven&#8217;t gone through the previous posts yet, I strongly recommend you to do that. You can find the links to the previous posts below. In our previous posts, we saw about the Angular 5 updates, an overview of the project and how to set up your first application in Angular 5. In this post, we are going to create few components and modules like routing, navigation, registration forms etc. So at the end of this article, you will be having a registration application [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>This post is a continuation of the course <em>Developing an Angular 5 App</em> series if you haven&#8217;t gone through the previous posts yet, I strongly recommend you to do that. You can find the links to the previous posts below. In our previous posts, we saw about the <a href="http://sibeeshpassion.com/category/client-side-technologies/angular/">Angular</a> 5 updates, an overview of the project and how to set up your first application in Angular 5. In this post, we are going to create few components and modules like routing, navigation, registration forms etc. So at the end of this article, you will be having a registration application with navigation and routing enables. I hope you will like this article.</p>
<h3><em>Developing an Angular 5 App</em> series</h3>
<p>These are the previous posts in this series. Please go ahead and have a look.</p>
<ol>
<li><a href="http://sibeeshpassion.com/what-is-new-and-how-to-set-up-our-first-angular-5-application/">What Is New and How to Set Up our First Angular 5 Application</a></li>
<li><a href="http://sibeeshpassion.com/angular-5-basic-demo-project-overview/">Angular 5 Basic Demo Project Overview</a></li>
</ol>
<h3><span id="source-code">Source Code</span></h3>
<p>You can always clone or download the source code <a href="https://github.com/SibeeshVenu/ng5">here</a></p>
<h3>Background</h3>
<p>So as I mentioned, here we are going to create an Angular 5 application which contains Registration form, Navigation, Routing etc.</p>
<h3>Let&#8217;s Develop Our Application</h3>
<p>We will be creating our application in a step by step manner so that you can easily follow up. No more talking now and let&#8217;s code it.</p>
<h4>Creating your first component</h4>
<p>As we discussed in our previous posts, a component is a set of combined functionality, in our case, we are going to create a component called Registration whose purpose is to serve all the codes for Registration.</p>
<p>You can create your components in two ways,</p>
<ol>
<li>Manually create a file called <em>registration.component.ts, </em>if you opt this method, you will have to register this component in <em>app.module.ts </em>yourself and also creating the template.</li>
<li>Using a command in NPM command prompt, this is an easy method, as it does all the background work for us.</li>
</ol>
<p>I am going to opt the second method. To create a component using your command prompt, you will have to run the following command.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">ng generate component {component name }
</pre>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">D:\SVenu\FullStackDevelopment\Angular\Angular5\ng5&gt;ng g component registration</pre>
<p>Once you run the command, the following processes will be happened.</p>
<ol>
<li>create src/app/registration/registration.component.html</li>
<li>create src/app/registration/registration.component.spec.ts</li>
<li>create src/app/registration/registration.component.ts</li>
<li>create src/app/registration/registration.component.scss</li>
<li>update src/app/app.module.ts (501 bytes)</li>
</ol>
<p>Now let us go back to our code folder and see the files. You can see your new files in app/registration folder. Here is how our registration.component.ts file looks like.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="js">import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-registration',
  templateUrl: './registration.component.html',
  styleUrls: ['./registration.component.scss']
})
export class RegistrationComponent implements OnInit {
  constructor() { }
  ngOnInit() {
  }
}
</pre>
<p>If you see the code, the command had created all of the code which we need to get started. The same component will be imported and added to our declarations in @NgModule in our <em>app.module.ts. </em>Please go ahead and see the same.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="js">import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { RegistrationComponent } from './registration/registration.component';


@NgModule({
  declarations: [
    AppComponent,
    RegistrationComponent
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
</pre>
<h4>Creating a registration form</h4>
<p>Now that we have created our component, let&#8217;s edit our component with needed text boxes and button. Go to your <em>registration.component.html </em>file and edit the content as preceding.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;p&gt;
  &lt;input type="text" placeholder="First Name" /&gt;
  &lt;input type="text" placeholder="Last Name" /&gt;
  &lt;input type="email" placeholder="Email" /&gt;
  &lt;input type="password" placeholder="Password" /&gt;
  &lt;input type="password" placeholder="Confirm Passwrod" /&gt;
  &lt;br/&gt;
  &lt;button&gt;Register&lt;/button&gt;
&lt;/p&gt;
</pre>
<h4>Creating a route for our new component</h4>
<p>Now our registration page is updated, and we are yet to create a route for the same right, let&#8217;s create it now and test our registration page.</p>
<p>To create a route you will have to do some set of changes.</p>
<h5>Make sure that you have one base element in your src/index.html file</h5>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;base href="/"&gt;</pre>
<h5>Now go to your app.module.ts file and import the RouterModule there</h5>
<pre class="EnlighterJSRAW" data-enlighter-language="js">import { RouterModule, Routes } from '@angular/router';</pre>
<h5>Create our Route Array</h5>
<pre class="EnlighterJSRAW" data-enlighter-language="js">const myRoots: Routes = [
  { path: 'register', component: RegistrationComponent }
];</pre>
<p>Here the path is the route name and component is the component which that path refers to.</p>
<h5>Configure the route in imports</h5>
<p>Once we create the routing array, it is time to configure it, using RouterModule.forRoot.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="js">@NgModule({
  declarations: [
    AppComponent,
    RegistrationComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    RouterModule.forRoot(myRoots)
  ],
  providers: [],
  bootstrap: [AppComponent]
})</pre>
<h5>Set our router outlet</h5>
<p>We have successfully configured our route, now we need to set where this pages/components to appear. To do so, go to your <em>app.component.html </em>and add the router-outlet. So the content of the route components will be displayed after the router-outlet tag.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;!--The content below is only a placeholder and can be replaced.--&gt;
&lt;div style="text-align:center"&gt;
  &lt;h1&gt;
    Welcome to {{title}}!
  &lt;/h1&gt;
  
&lt;/div&gt;
&lt;router-outlet&gt;&lt;/router-outlet&gt;
</pre>
<p>Now if you run our application by following the route as <em>http://localhost:4200/register</em> you can see our registration page as preceding.</p>
<div id="attachment_12549" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/11/Sample_Registration_Form-e1510816878711.png"><img fetchpriority="high" decoding="async" aria-describedby="caption-attachment-12549" class="wp-image-12549 size-full" src="http://sibeeshpassion.com/wp-content/uploads/2017/11/Sample_Registration_Form-e1510816878711.png" alt="Sample_Registration_Form" width="634" height="104" /></a><p id="caption-attachment-12549" class="wp-caption-text">Sample_Registration_Form</p></div>
<p>Isn&#8217;t this registration form too basic, let&#8217;s style them now?</p>
<h4>Style registration page using material design</h4>
<p>Before we do anything, we need to install angular-material to our project. So that we can use the styles which are available there.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">npm install --save @angular/material @angular/cdk</pre>
<p>By any chance, if you get an error as below,</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">D:\SVenu\FullStackDevelopment\Angular\Angular5\ng5&gt;npm install --save @angular/material @angular/cdk
npm ERR! path D:\SVenu\FullStackDevelopment\Angular\Angular5\ng5\node_modules\fsevents\node_modules\dashdash\node_modules
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall scandir
npm ERR! Error: EPERM: operation not permitted, scandir 'D:\SVenu\FullStackDevelopment\Angular\Angular5\ng5\node_modules\fsevents\node_modules\dashdash\node_modules'
npm ERR! { Error: EPERM: operation not permitted, scandir 'D:\SVenu\FullStackDevelopment\Angular\Angular5\ng5\node_modules\fsevents\node_modules\dashdash\node_modules'
npm ERR! stack: 'Error: EPERM: operation not permitted, scandir \'D:\\SVenu\\FullStackDevelopment\\Angular\\Angular5\\ng5\\node_modules\\fsevents\\node_modules\\dashdash\\node_modules\'',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'scandir',
npm ERR! path: 'D:\\SVenu\\FullStackDevelopment\\Angular\\Angular5\\ng5\\node_modules\\fsevents\\node_modules\\dashdash\\node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
</pre>
<p>You should try running the following command before you execute the above command again.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">cmd.exe npm</pre>
<p>You may also need to install the animation as well</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">npm install --save @angular/animations</pre>
<p>Once you have installed it, we need to import the some of the modules in the app.module.ts file as preceding.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="js">import { MatButtonModule, MatCardModule, MatInputModule, MatSnackBarModule, MatToolbarModule } from '@angular/material';</pre>
<p>Now add those components to our import list in @NgModule.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="js">@NgModule({
  declarations: [
    AppComponent,
    RegistrationComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    MatButtonModule, MatCardModule, MatInputModule, MatSnackBarModule, MatToolbarModule,
    RouterModule.forRoot(myRoots)
  ],
  providers: [],
  bootstrap: [AppComponent]
})</pre>
<p>Let&#8217;s go back to our registration.component.html file and do some design changes.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;mat-card&gt;
  &lt;mat-input-container&gt;
    &lt;input matInput type="text" placeholder="First Name" /&gt;
  &lt;/mat-input-container&gt;
  &lt;mat-input-container&gt;
    &lt;input matInput type="text" placeholder="Last Name" /&gt;
  &lt;/mat-input-container&gt;
  &lt;mat-input-container&gt;
    &lt;input matInput type="email" placeholder="Email" /&gt;
  &lt;/mat-input-container&gt;
  &lt;mat-input-container&gt;
    &lt;input matInput type="password" placeholder="Password" /&gt;
  &lt;/mat-input-container&gt;
  &lt;mat-input-container&gt;
    &lt;input matInput type="password" placeholder="Confirm Passwrod" /&gt;
  &lt;/mat-input-container&gt;
  &lt;br /&gt;
  &lt;button mat-raised-button color="primary"&gt;Register&lt;/button&gt;
&lt;/mat-card&gt;
</pre>
<p>We also need to include one material CSS in our Style.scss file.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="css">@import '~@angular/material/prebuilt-themes/deeppurple-amber.css';</pre>
<p>Now let&#8217;s run our application and see our registration page.</p>
<div id="attachment_12552" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/11/Material_Angular_Form-e1510836044744.png"><img decoding="async" aria-describedby="caption-attachment-12552" class="wp-image-12552 size-full" src="http://sibeeshpassion.com/wp-content/uploads/2017/11/Material_Angular_Form-e1510836044744.png" alt="Material_Angular_Form" width="634" height="281" /></a><p id="caption-attachment-12552" class="wp-caption-text">Material_Angular_Form</p></div>
<p>That&#8217;s cool, we have done it.</p>
<h4>Create Home and Navigation Components</h4>
<p>We know how to create new components now using generate command right, let&#8217;s create a new component for Home and Navigation.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="shell">ng g component home 

ng g component nav</pre>
<p>As we used the commands to create the components, the same will be imported in our app.module.ts automatically, so we don&#8217;t need to worry about it.</p>
<p>Now let&#8217;s edit our nav component and use a material design for the navigation buttons.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;mat-toolbar color="primary"&gt;
  &lt;button mat-button routerLink="/"&gt;Home&lt;/button&gt;
  &lt;button mat-button routerLink="/register"&gt;Register&lt;/button&gt;
&lt;/mat-toolbar&gt;
</pre>
<p>Here routerLink property specifies the route where we need to redirect to. We are not done yet, we need to use this component on our app.component.html page to see this navigation.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="html">&lt;!--The content below is only a placeholder and can be replaced.--&gt;
&lt;div style="text-align:center"&gt;
  &lt;h1&gt;
    Welcome to {{title}}!
  &lt;/h1&gt;
  &lt;app-nav&gt;&lt;/app-nav&gt;
&lt;/div&gt;
&lt;router-outlet&gt;&lt;/router-outlet&gt;
</pre>
<p>And also add our new route for our HomeComponent. So go to your app.module.ts and edit your route as follows.</p>
<pre class="EnlighterJSRAW" data-enlighter-language="js">const myRoots: Routes = [
  { path: '', component: HomeComponent },
  { path: 'register', component: RegistrationComponent }
];</pre>
<p>Let&#8217;s give it a try now, I am sure that you will be seeing an output as preceding.</p>
<div id="attachment_12553" style="width: 644px" class="wp-caption alignnone"><a href="http://sibeeshpassion.com/wp-content/uploads/2017/11/Nav_Demo-e1510838066336.png"><img decoding="async" aria-describedby="caption-attachment-12553" class="wp-image-12553 size-full" src="http://sibeeshpassion.com/wp-content/uploads/2017/11/Nav_Demo-e1510838066336.png" alt="Nav_Demo" width="634" height="250" /></a><p id="caption-attachment-12553" class="wp-caption-text">Nav_Demo</p></div>
<p>That&#8217;s all for today. In our next article, we will start to do some validations and set up two-way data binding, so that the model values can be passed to the server. Till then bye.</p>
<h3><span id="conclusion">Conclusion</span></h3>
<p>Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.</p>
<h3><span id="your-turn-what-do-you-think">Your turn. What do you think?</span></h3>
<p>A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://sibeeshpassion.com/generating-your-first-components-and-modules-in-angular-5-app/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
