I am newbie to angularjs2.
I have prepared Login Page using angularjs2 with validation.But i have getting some error.
Here i have attached my code with error.
VIEW CODE :
<form [formGroup]="loginForm" (ngSubmit)="onSubmit(form.value)" class="smart-form client-form">
<header>Sign In</header>
<fieldset>
<section>
<label class="label">UserName</label>
<label class="input">
<i class="icon-append fa fa-user"></i>
<input type="text" id="username" [formControl]="form.controls['username']" >
<control-messages [control]="loginForm.controls.username"></control-messages>
<b class="tooltip tooltip-top-right">
<i class="fa fa-user txt-color-teal"></i>
Please enter username
</b>
</label>
</section>
<section>
<label class="label">Password</label>
<label class="input">
<i class="icon-append fa fa-lock"></i>
<input type="password" id="password" formControlName="password">
<control-messages [control]="loginForm.controls.password"></control-messages>
<b class="tooltip tooltip-top-right">
<i class="fa fa-lock txt-color-teal"></i>
Enter your password
</b>
</label>
<div class="note">
<a href="forgotpassword">Forgot password?</a>
</div>
</section>
</fieldset>
<footer>
<button type="submit" class="btn btn-primary" [disabled]="!loginForm.valid">
Sign in
</button>
</footer>
CONTROLLER :
import { Component } from '@angular/core';
import {FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES} from '@angular/forms';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import { ValidationService } from 'app/validation.service';
@Component({
moduleId: module.id,
selector: 'login-app',
templateUrl: 'login.html',
styleUrls: ['login.css'],
directives: [FORM_DIRECTIVES, REACTIVE_FORM_DIRECTIVES]
})
export class LoginComponent
{
form: FormGroup;
userForm: any;
constructor(private formBuilder: FormBuilder) {
this.loginForm = this.formBuilder.group({
'username': ['', Validators.required],
'password': ['', [Validators.required, Validators.minLength(10)]]
});
console.log(this.userForm);
}
saveData() {
if (this.loginForm.dirty && this.loginForm.valid) {
alert(`Username: ${this.loginForm.value.username} Password: ${this.loginForm.value.password}`);
}
}
}
NGMODULE :
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { ControlMessagesComponent } from './control-messages.component';
import { ValidationService } from './validation.service';
import { LoginComponent } from './login/login.component';
import { ProjectgroupsComponent } from './Projectgroups/projectgroups.component';
import { PageNotFoundComponent } from './PageNotFound/pagenotfound.component';
/*
const appRoutes: Routes = [
{ path: 'login', component: LoginComponent },
{ path: '', component: LoginComponent },
{path: '/404', name: 'NotFound', component: PageNotFoundComponent},
{path: '**', redirectTo: 404}
];
*/
export const routeConfig:Routes = [
{ path: 'login', component: LoginComponent },
{
path: "**",
component: PageNotFoundComponent
},
{
path: "",
component: LoginComponent
}
];
@NgModule({
imports: [
BrowserModule,
FormsModule,
ReactiveFormsModule,
RouterModule.forRoot(routeConfig)
],
exports: [
FormsModule,
ReactiveFormsModule
],
declarations: [
ControlMessagesComponent,
AppComponent,
LoginComponent,
ProjectgroupsComponent,
PageNotFoundComponent
],
providers: [ ValidationService ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
export class AppRoutesModule {}
platformBrowserDynamic().bootstrapModule(AppModule)
;
My question is :
how can i resolve this error?
Is there any other possible solutions to avoid this error?
All suggestions are acceptable.
Thanks to all in advance.