In our previous article, we learned how to create services and use them in multiple components. Now, we are going to talk about forms. Forms are really important to get the data from the users.
Let's say a user wants to sign in to our website. He/she must need to enter the username and password and then, we need to validate those credentials before the user enters the website. And we want to validate and show the errors if there is any wrong information while the user logs in. So, we must be able to access the data that user can enter in an input form.
Let's say a user wants to sign in to our website. He/she must need to enter the username and password and then, we need to validate those credentials before the user enters the website. And we want to validate and show the errors if there is any wrong information while the user logs in. So, we must be able to access the data that user can enter in an input form.
In this article, we are going to see how we can fetch the data of the form and how we can validate the data and how we can handle different kinds of errors on that form.
Let's open app.component.ts and app.component.html which are both empty.
Now, I have prewritten CSS which you can write as it is; otherwise, you can write on your own also.
Code
I will go back to app.component.html and design the form with the below HTML code.
- *{
- box - sizing: border - box;
- }.container {
- display: block;
- background: #f4f4f4;
- max - width: 650 px;
- margin - top: 20 px;
- margin - left: auto;
- margin - right: auto;
- padding: 10 px 40 px;
- text - align: center;
- position: relative;
- font - family: sans - serif;
- font - size: 15 px;
- }
- p {
- font - size: 40 px;
- font - weight: 200;
- line - height: 100 % ;
- font - weight: 700;
- color: #555459;
- margin-top: 20px;
- margin-left: 0px;
- margin-bottom: 20px;
- }
- input, select{
- width:100%;
- display: inline-block;
- padding:15px;
- font-weight: 100;
- font-size: 20px;
- margin:5px 0;
- color:# 3 f3f3f;
- }


Dharmraj ThakurPosted Jan 12, 2018, 1:14 AM
Nice article... and topic