Development › Angular 4 FORMS Confusion

Angular 4 FORMS Confusion

Angular 4 Forms Confusion | Phaedra Solutions
Nabeela Anwar, Content Marketer & Strategist at Phaedra Solutions
Nabeela Anwar
Content Marketer & Strategist
Author
Last edited:06/18/2026
Recently Updated on June 18, 2026
Index

Example code of wrong concept but it also works fine thats why we all were confused.

Html part

Email

Login

TypeScript part


import { FormBuilder, FormGroup, Validators } from ‘@angular/forms’;
@Component({
selector: ‘page-login’,
templateUrl: ‘login.html’,
})
export class LoginPage {
loginForm: FormGroup;
data: any;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private _userService: UserService,
private login: FormBuilder
)
{
this.createForm();
this.data = {
userName: “”
}
}
onSubmit() {
this._userService.userLogin({ data: this.data })
.subscribe(res => {

},
errorMsg => {

});
}

createForm() {
this.loginForm = this.login.group({
userName: [“”, Validators.required] });
}
}

Note:

This working fine but not a right way

Right Approach…Very Important

Import form modules in parent module file


import { FormsModule, ReactiveFormsModule } from ‘@angular/forms’;

Then Import


imports: [
FormsModule,
ReactiveFormsModule
]

Html part

Email

Login

TypeScript part


import { FormBuilder, FormGroup, Validators } from ‘@angular/forms’;

@Component({
selector: ‘page-login’,
templateUrl: ‘login.html’,
})
export class LoginPage {
loginForm: FormGroup;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private _userService: UserService,
private login: FormBuilder
)
{
this.createForm();
}

// if you want to set value of form controller name use this command.
// this.login.controls[‘userName’].setValue(‘John’);

onSubmit() {
this.username = this.login.get(‘userName’).value;
this.data = {
username: this.username
}
this._userService.userLogin({ data: this.data })
.subscribe(res => {

},
errorMsg => {

});
}

createForm() {
this.loginForm = this.login.group({
userName: [“”, Validators.required] });
}
}

Conclusion:

So, the conclusion is that me must use right approach because angular has defined this approach in their documentation. And if we want to improve our coding skills so then we should work according to documentation.

Share this blog
Nabeela Anwar, Content Marketer & Strategist at Phaedra Solutions
Nabeela Anwar
Content Marketer & Strategist
Author
Nabeela is a content writer with 5+ years of experience in digital content and marketing strategy. Her articles have helped brands improve engagement by 2x and rank higher on search engines. Her writing turns complex ideas into engaging content that resonates with the right audience. She focuses on creating articles that inform, inspire action, and support business growth.
More on
Looking For Your Next Big breakthrough? It’s Just a Blog Away.

Great! We’ve received your information.

What are you looking to achieve?*

When are you planning to start?*

What best describes your involvement in this project?*

Select Your Budget*

Select a Service or Technology*