Task 7
Task 7
First, check your current Node.js and npm versions to ensure you're aware of what you're
working with. In Command Prompt or PowerShell, run:
The Angular CLI is a powerful command-line interface tool that helps streamline Angular
development. Install it in your program folder by moving in your program folder by using cd
command:
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.1
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
4.
Check the installed Angular version, the version will display:
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.2
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
5. Create a New Angular Project named “Reactive” with the Installed CLI
6. Follow the prompts, and once the project is created, you can start the
development server by moving in the folder and using ng serve:
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.3
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
Once the server starts, the Angular live development server will start.
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.4
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.5
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.6
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
<br>
<label for="lname"> Last Name </label>
<input type="text" id="lname" placeholder="Enter your last name"
formControlName="lastaname">
<br>
<br>
<label for="email"> Email ID </label>
<input type="email" id="email" placeholder="Enter your last email"
formControlName="email">
<br>
<br>
<label for="country">Country</label>
<select id="country" formControlName="country">
<option value="australia">Australia</option>
<option value="canada">Canada</option>
<option value="usa" selected>USA</option>
</select>
<br>
<br>
<label for="gender">Gender</label>
<input type="radio" id="male" value="male" formControlName="gender">
<label for="male">Male</label>
<input type="radio" id="female" value="female"
formControlName="gender">
<label for="male">Female</label>
<br>
<br>
<label>Hobbies</label>
<div class="form-inline">
<label><input type="checkbox" value="sports" checked
formControlName="hobbies">Sports</label>
<label><input type="checkbox" value="movies" formControlName="hobbies"
>Movies</label>
<label><input type="checkbox" value="music" formControlName="hobbies"
>Music</label>
</div><br>
<input type="submit" value="Submit" id="btn">
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.7
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
</form>
10. Add the styles of the HTML page by typing the following code in
app.component.css
input[type=text],[type=email],select{
width:100%;
padding:12px 20px;
margin:8px 0;
display:inline-block;
border:1px solid #ccc;
border-radius:4px;
box-sizing:border-box;
}
input[type=submit]{
width:100%;
background-color:#4CAF50;
color:white;
padding:14px 20px;
margin:8px 0;
border:none;
border-radius:4px;
cursor:pointer;
}
input[type=submit]:hover{
background-color:#45a049;
}
.form{
border-radius:5px;
background-color:#f2f2f2;
padding:20px;
width: 420px;
margin:10px auto;
}
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.8
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit{
title = 'Reactive';
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.9
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
FormGroup and FormControl: These classes are used to create and manage
the form controls programmatically.
ngOnInit(): Initializes the form and its fields when the component is loaded.
onSubmit(): This function gets triggered when the form is submitted, and the
form data is logged to the console.
This file is the main module of the Angular app, and it configures the
application to use reactive forms by importing the necessary modules.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ReactiveFormsModule } from '@angular/forms'; //INCLUDE THIS LINE
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ReactiveFormsModule //INCLUDE THIS LINE
],
providers: [],
bootstrap: [AppComponent]
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.10
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
})
export class AppModule { }
ReactiveFormsModule: This module enables the use of reactive forms in
Angular. It must be imported to use FormGroup, FormControl, and other
reactive form features.
BrowserModule: The basic Angular module required for any web app.
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.11
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
After entering the inputs the final output gets reflected in the console as,
Result :
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.12
10211CS212: WEB AND MOBILE APPLICATION DEVELOPMENT
Thus the above program was executed and output was verified successfully.
Lab Ex. Mr. S. Vasudevan, Assistant Professor / CSE, Vel Tech Page 1.13