After clicking on button popup not showing in angulr6 project - angular6

I am doing project in angular6. I have created registration form, and I have called two functions at a time, one function for form submit, and other for open popup,as shown in the code. After clicking on submit button, the form values need to be show in popup, with final submit button, but here after clicking on submit button form getting submit but popup not getting open. I am not getting where I have done mistake. Any help please
registration.html
In this file I have called two functions at a time.
<nav class="navbar navbar-expand-lg">Header
</nav>
<div class="container">
<form [formGroup]="addForm" (ngSubmit)=[onSubmit(addForm.value),openModal()]>
<h2 class="text-center mt-3">Registration Form</h2>
<div class="card-header mt-3 mb-3">Student Registration</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="usn"><strong>USN</strong></label>
<input type="usn" formControlName="usn" placeholder="usn" name="usn" class="form-control" id="usn">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="firstName"><strong>First Name</strong></label>
<input type="firstName" formControlName="firstName" placeholder="FirstName" name="firstName" class="form-control" id="firstName" ngModel>
</div>
</div>
</div>
<button class="btn btn-success mx-auto d-block" >Submit</button>
</div>
registration.ts
import { Component, OnInit } from '#angular/core';
import {FormBuilder, FormGroup, Validators} from "#angular/forms";
import {Router} from "#angular/router";
import {Inject} from '#angular/core';
import {MatDialog, MatDialogRef, MAT_DIALOG_DATA} from '#angular/material';
import { DisplayDataComponent } from '../display-data/display-data.component';
#Component({
selector: 'app-student-parent-registration',
templateUrl: './student-parent-registration.component.html',
styleUrls: ['./student-parent-registration.component.css']
})
export class StudentParentRegistrationComponent implements OnInit {
constructor(private formBuilder: FormBuilder, private router: Router, public dialog: MatDialog) { }
addForm: FormGroup;
ngOnInit() {
console.log("ngOnInit called")
this.addForm = this.formBuilder.group({
usn:[''],
firstName:['']
});
}
onSubmit(data) {
console.log(data);`
openModal(){
console.log("calling")
const dialogRef = this.dialog.open(DisplayDataComponent, {
width: '250px',
});
dialogRef.afterClosed().subscribe(result => {
console.log('The dialog was closed');
});
}
}
app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import {FormsModule, ReactiveFormsModule} from '#angular/forms';
import { FormGroup } from '#angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { StudentParentRegistrationComponent } from './student-parent-registration/student-parent-registration.component';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { DisplayComponent } from './display/display.component';
import { DisplayDataComponent } from './display-data/display-data.component';
import {MatDialogModule} from '#angular/material/dialog';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
#NgModule({
declarations: [
AppComponent,
StudentParentRegistrationComponent,
DisplayComponent,
DisplayDataComponent
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
ReactiveFormsModule,
MatDialogModule,
BrowserAnimationsModule,
BsDatepickerModule.forRoot()
],
entryComponents: [
DisplayDataComponent
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
After clicking on button not getting popup

Seems like you are not closing your form tag

Related

Angular Registration page does not load after adding methods & services

I created an email authentication based registration page in my angular app, added the code with submission functionality (onSubmit) to register.component.html and the methods & services in register.component.ts & UserService.ts files.
Problem:
After adding the code as shared below, the registration page (register.component.html) itself does not load when I click the corresponding router link;
the issue is not with routing as it all worked fine until I added the methods & services.
No error thrown at time of compilation.
Pls suggest what to do.
Showing my respective files in register component:
register.component.html
<style>
.form-container {
display: flex;
align-items: center;
justify-content: center;
height: 50vh;
flex-wrap: wrap;
margin-top:25px;
}
.form-row {
display: flex;
flex-wrap: nowrap;
}
.form-group {
flex: 1;
margin: 20px;
}
</style>
<div class="registrationForm" type="FormGroup">
<form (ngSubmit)="onSubmit()">
<div class="form-row">
<div class="form-group">
<label for="exampleInputUsername">Username</label>
<input type="text" class="form-control" id="exampleInputUsername" placeholder="eg. Niti Sara">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Email:</label>
<input type="email" [(ngModel)]="email" name="email" required class="form-control" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="eg. john#doe.com">
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="exampleInputPhone">Phone No.</label>
<input type="number" class="form-control" id="exampleInputPhone" placeholder="eg. +1300 400 5000" >
</div>
<div class="form-group">
<label for="exampleInputUrl">Website URL</label>
<input type="link" class="form-control" id="exampleInputUrl" placeholder="eg. https://example.com/">
</div>
</div>
<div class="form-row">
<div class="form-group">
<label for="exampleInputCname">Your Organisation</label>
<input type="text" class="form-control" id="exampleInputCname" placeholder="eg. Enter Your Organisation Name">
</div>
</div>
<div class="form-row">
<label>Password:</label>
<input type="password" [(ngModel)]="password" name="password" required>
</div>
<button type="submit" class="btn btn-primary" style="margin-left:220px;margin-top:20px;">Submit</button>
</form>
</div>
register.component.ts
import { Component, OnInit } from '#angular/core';
import { Router } from '#angular/router';
import { UserService } from 'src/app/register/UserService'; //import the user service
import { FormBuilder, FormGroup, Validators } from '#angular/forms'; //import form modules
#Component({
selector: 'app-register',
templateUrl: './register.component.html',
styleUrls: ['./register.component.less']
})
export class RegisterComponent implements OnInit {
registrationForm: FormGroup;
email:string ='';
password:string ='';
submitted = false;
constructor(
private formBuilder: FormBuilder,
private router: Router,
private userService: UserService,
)
{
this.registrationForm = this.formBuilder.group({});
}
ngOnInit() {
this.registrationForm = this.formBuilder.group({
email: [this.email, [Validators.required, Validators.email]],
password: [this.password, [Validators.required, Validators.minLength(6)]],
});
}
// convenience getter for easy access to form fields
get f() { return this.registrationForm.controls; }
onSubmit() {
this.submitted = true;
if (this.registrationForm.invalid) {
return;
}
//call the user service to register the user
this.userService.register(this.registrationForm.controls['email'].value, this.registrationForm.controls['password'].value)
.subscribe(data => {
// handle the response
});
//error handling can b introduced
}
}
UserService.ts
import { Injectable } from '#angular/core';
import { HttpClient } from '#angular/common/http';
import { Observable } from 'rxjs';
#Injectable({
providedIn: 'root'
})
export class UserService {
private baseUrl = 'http://localhost:8080/'; // replace with your backend URL
constructor(private http: HttpClient) { }
//check the use of 'Observable'
register(email: string, password: string): Observable<any> {
const data = {
email: email,
password: password
};
return this.http.post(`${this.baseUrl}/register`, data);
}
}
This is what my browser console says:
ERROR Error: Uncaught (in promise): NullInjectorError: R3InjectorError(AppModule)[FormBuilder -> FormBuilder -> FormBuilder]:
NullInjectorError: No provider for FormBuilder!
Just import HttpClientModule in your app.module.ts. That's the only problem I can see here.
The problem was due to not adding FormsModule & ReactiveFormsModule in both app.module.ts & register.component.spec.ts
app.module.ts
import { FormsModule } from '#angular/forms';
import { ReactiveFormsModule } from '#angular/forms';
imports: [
FormsModule,
ReactiveFormsModule
],
register.component.spec.ts
import { FormsModule } from '#angular/forms';
import { ReactiveFormsModule } from '#angular/forms';
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ RegisterComponent ],
imports: [
FormsModule, // << ----- add this line
ReactiveFormsModule // << ----- add this line
]
})

The Validators And Errors Are Not Working In Angular 9

I have started working on Angular 9 and I am using the Reactive Form in Angular 9 but the problem is that the validators and errors are not working for the form.
This is my app.module.ts:
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { FormsModule, ReactiveFormsModule } from '#angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
FormsModule,
ReactiveFormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
This is my app.component.ts:
import { Component, OnInit } from '#angular/core';
import { FormGroup, FormControl, Validators, FormBuilder } from '#angular/forms';
import { MustMatch } from './_helpers/must-match.validator';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'my-assignment';
submitted = false;
show: boolean;
profileForm: FormGroup;
constructor(private fb: FormBuilder) {
this.show = true;
}
ngOnInit() {
this.profileForm = this.fb.group({
email: ['', [Validators.required, Validators.pattern('[a-z0-9.#]*')]],
password: ['', [Validators.required, Validators.minLength(8)]],
confirmpassword: ['', Validators.required],
}, {
validator: MustMatch('password', 'confirmpassword')
});
}
get f() { return this.profileForm.controls; }
onSubmit() {
// TODO: Use EventEmitter with form value
console.warn(this.profileForm.value);
}
// click event function toggle
password() {
this.show = !this.show;
}
}
This is my app.component.html:
<div class="jumbotron">
<div class="container">
<div class="row">
<div class="col-md-6 offset-md-3">
<form style="margin-top: 100px;" [formGroup]="profileForm" (ngSubmit)="onSubmit()">
<div class="form-group">
<label for="firstName">Email: </label>
<input type="text" placeholder="Email" formControlName="email">
<div *ngIf="f.email.hasError('pattern')">
Oops, wrong pattern buddy!
</div>
</div>
<div class="form-group">
<label for="password">Password: </label>
<input [type]="show ? 'text' : 'password'" placeholder="Password" formControlName="password">
<div *ngIf="submitted && f.password.errors" class="invalid-feedback">
<div *ngIf="f.password.errors.required">Password is required</div>
<div *ngIf="f.password.errors.minlength">Password must be at least 6 characters</div>
</div>
</div>
<div class="form-group">
<label for="confirmpassword">Confirm Password: </label>
<input type="password" placeholder="Confirm Password" formControlName="confirmpassword" class="form-control" [ngClass]="{ 'is-invalid': submitted && f.confirmPassword.errors }" />
<div *ngIf="submitted && f.confirmpassword.errors" class="invalid-feedback">
<div *ngIf="f.confirmpassword.errors.required">Confirm Password is required</div>
<div *ngIf="f.confirmpassword.errors.mustMatch">Passwords must match</div>
</div>
</div>
<button (click)="password()">Show Password</button>
<button type="submit" [disabled]="!profileForm.valid">Submit</button>
</form>
</div>
</div>
</div>
</div>
This is my must-match.validator.ts:
import { FormGroup } from '#angular/forms';
// custom validator to check that two fields match
export function MustMatch(controlName: string, matchingControlName: string) {
return (formGroup: FormGroup) => {
const control = formGroup.controls[controlName];
const matchingControl = formGroup.controls[matchingControlName];
if (matchingControl.errors && !matchingControl.errors.mustMatch) {
// return if another validator has already found an error on the matchingControl
return;
}
// set error on matchingControl if validation fails
if (control.value !== matchingControl.value) {
matchingControl.setErrors({ mustMatch: true });
} else {
matchingControl.setErrors(null);
}
};
}
core.js:6185 ERROR TypeError: Cannot read property 'errors' of undefined
Any help is much appreciated.
You have a typo : confirmPassword ( *ngIf="f.confirmPassword.errors.required").
It's confirmpassword everywhere else.

RouterLink seems to just reload the current page most of the time

I have added page navigation in my webapp using routerlinks and for some reason the page just reloads most of the time , and at the other times it works fine, very randomly.
I am stumped, especially as to why it works randomly. Any insight at all would be helpful.
Relevant code:
app-routing.module.ts:
import { NgModule } from '#angular/core';
import { Routes, RouterModule } from '#angular/router';
import { ProfileComponent } from './views/profile/profile.component';
import { PwSetupComponent } from './views/pw-setup/pw-setup.component';
import { ChangePwComponent } from './views/change-pw/change-pw.component';
import { EditProfileComponent } from './views/edit-profile/edit-profile.component';
const routes: Routes = [
{path: '', redirectTo: 'pwSetup', pathMatch: 'full'},
{path: 'pwSetup', component: PwSetupComponent},
{path: 'profile', component: ProfileComponent},
{path: 'changePw', component: ChangePwComponent},
{path: 'editProfile', component: EditProfileComponent}
];
#NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
pw-setup.component.html:
<div style="padding-top: 10px;padding-left:10px; ">
<img src="./assets/img/og-favicon.png" width="50" height="50">
</div>
<div class="container-fluid outer-container" style="height:80%;min-height:550px;">
<div class="row middle-container">
<div class="col-s-12 container inner-container">
<p >Lets set up your password</p>
<form >
<div class="form-group">
<label for="username" class="label1">EMAIL ADDRESS</label>
<p>email#id.com</p>
</div>
<div class="form-group">
<label for="username" class="label1">TEAM NAME</label>
<p>name of team</p>
</div>
<div class="form-group">
<label for="password" class="label1">PASSWORD</label>
<input type="password" formControlName="password" class="form-control" />
</div>
<div class="form-group">
<label for="password" class="label1">CONFIRM PASSWORD</label>
<input type="password" formControlName="password" class="form-control" />
</div>
<label class="label2"><input id="rememberme" name="rememberme" value="remember" type="checkbox" /> Remember me</label>
<div class="form-group">
<button mat-flat-button class="blue-button">
<a [routerLink]="['/profile']" style="color: white; text-decoration: none;" >PROCEED</a>
</button>
</div>
</form>
<router-outlet></router-outlet>
</div>
</div>
</div>
app.module.ts:
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { MatButtonModule, MatNativeDateModule, MatIconModule, MatSidenavModule, MatListModule, MatToolbarModule} from '#angular/material';
import { BrowserAnimationsModule } from '#angular/platform-browser/animations';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { SideNavComponent } from './components/side-nav/side-nav.component';
import { AvatarModule } from 'ngx-avatar';
import { HttpClientModule } from '#angular/common/http';
import { MatTableModule } from '#angular/material/table';
import { RightNavComponent } from './components/right-nav/right-nav.component';
import { HighchartsChartComponent } from 'highcharts-angular';
import { ProfileComponent } from './views/profile/profile.component';
import { PwSetupComponent } from './views/pw-setup/pw-setup.component';
import { ChangePwComponent } from './views/change-pw/change-pw.component';
import { EditProfileComponent } from './views/edit-profile/edit-profile.component';
#NgModule({
declarations: [
AppComponent,
SideNavComponent,
RightNavComponent,
HighchartsChartComponent,
ProfileComponent,
PwSetupComponent,
ChangePwComponent,
EditProfileComponent
],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
MatButtonModule,
MatNativeDateModule,
MatIconModule,
MatSidenavModule,
MatListModule,
MatToolbarModule,
AvatarModule,
HttpClientModule,
MatTableModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
There are also no console errors.
The routerLink directive applied to an a element sets an href attribute upon this element.
I guess the same exception is thrown on click but the event still bubbles up and then the default behavior is executed and the page location is changed. As this happens really fast, you don't notice the error.
Try preserving the console logs even after page relaod, the error should be there.
If error continues , try change <a> tag to <button> tag and check .

After login home page loaded twice in angular 6

As I am new to angular, I am having a login page. I clicked on sign in button it's redirecting to the home page but its loading twice. In my angular web application, there are different starter component i.e header, footer, content, left sidebar. when my application loads and login hits by default that time I am hiding the left sidebar, header, footer, content. then after click on signin button its load home page twice. so I am not getting what is an issue. I am using AdminLTE Template.
Can any one suggest?
**login.component.html**
<body class="hold-transition login-page">
<div class="login-box">
<div class="login-logo">
<b>OneMigrate</b>
</div>
<!-- /.login-logo -->
<div class="login-box-body">
<p class="login-box-msg">Sign in to start your session</p>
<form>
<div class="form-group has-feedback">
<input type="email" class="form-control" placeholder="Email">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="Password">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<!-- <div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox"> Remember Me
</label>
</div>
</div> -->
<!-- /.col -->
<div class="col-xs-4"></div>
<div class="col-xs-4">
<button (click)="signin()" class="btn btn-primary btn-block btn-flat">Sign In</button>
</div>
<!-- /.col -->
<div class="col-xs-4"></div>
</div>
</form>
</div>
<!-- /.login-box-body -->
</div>
<!-- /.login-box -->
</body>
**app-routing.module.ts**
import { AdminDashboard2Component } from './../admin/admin-dashboard2/admin-dashboard2.component';
import { AdminDashboard1Component } from './../admin/admin-dashboard1/admin-dashboard1.component';
import { StarterComponent } from './../starter/starter.component';
import { NewRunDetailsComponent } from '../newrundetails/new-run-details.component'
import { EnvironmentSettingComponent } from '../environmentsetting/environment-setting.component';
import { AdminComponent } from './../admin/admin.component';
import { NgModule } from '#angular/core';
import { CommonModule } from '#angular/common';
import { RouterModule } from '#angular/router';
import { HomeComponent } from '../home/home.component';
import { RunDetailsComponent } from '../rundetails/run-details.component'
import { UploadfileComponent} from '../uploadfile/uploadfile.component';
import { RunhistoryComponent} from '../runhistory/runhistory.component';
import { AppInsightsService } from '../services/app-insights.service';
import { DetailrunhistoryComponent} from '../detailrunhistory/detailrunhistory.component';
import { PendingRunsComponent } from '../pendingruns/pendingruns.component';
import { PendingRunsDetailComponent} from '../pendingrunsdetail/pendingrunsdetail.component';
import { LoginComponent } from '../login/login.component';
#NgModule({
imports: [
RouterModule.forRoot([
{ path: '', redirectTo: '/login', pathMatch: 'full' },
{ path: 'home', component: HomeComponent },
{ path: 'newrundetails', component: NewRunDetailsComponent },
{ path: 'environmentsetting', component: EnvironmentSettingComponent},
{ path: 'rundetails', component: RunDetailsComponent},
{ path: 'pendingruns', component: PendingRunsComponent},
{ path: 'runhistory', component: RunhistoryComponent},
{ path: 'detailrunhistory', component:DetailrunhistoryComponent},
{ path: 'pendingrunsdetail',component:PendingRunsDetailComponent},
{ path: 'login',component:LoginComponent},
],{ useHash: true })
],
declarations: [],
exports: [ RouterModule]
})
export class AppRoutingModule { }
**login.component.ts**
import { Component, OnInit } from '#angular/core';
import { Router } from '#angular/router';
#Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
// public wrapper: boolean = false;
constructor(private router: Router) { }
ngOnInit() {
}
signin(){
this.router.navigate(['home']);
}
}
**app.component.ts**
import { Component, OnInit } from '#angular/core';
import { Router,NavigationStart } from '#angular/router';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
public title = 'app';
public wrappercontent: boolean = false;
constructor(private router: Router) {
}
ngOnInit(): void {
// debugger;
this.router.navigate(['login']);
// this.wrappercontent=true;
this.router.events.forEach((event) => {
if (event instanceof NavigationStart) {
if (event['url'] == '/login') {
this.wrappercontent=false;
} else{
this.wrappercontent=true;
}
}
});
}
}
**app.component.html**
<router-outlet></router-outlet>
<body hold-transition="" class="skin-blue sidebar-mini" style="height: auto;">
<div class="wrapper" *ngIf="wrappercontent">
<app-starter-header ></app-starter-header>
<app-starter-left-side></app-starter-left-side>
<app-starter-content></app-starter-content>
<app-starter-footer></app-starter-footer>
<app-starter-control-sidebar></app-starter-control-sidebar>
<div class="control-sidebar-bg"></div>
</div>
</body>
**home.component.html**
<div class="row img_full" *ngIf="this.show">
<div class="col-sm-1"></div>
<div class="col-sm-8">
<div>
<div>
<h3 class="box-title"></h3>
</div>
<div class="loader" *ngIf="showLoader"><i class="fa fa-spinner fa-spin"></i></div>
<div class="box-body" *ngIf="!showLoader">
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-4">
<button (click)="newRun()" class="pull-right button newRun">
<img src="/assets/images/NewRun_white.png" class="newrun_btn" /> NEW RUN
</button>
</div>
<div class="col-sm-1"></div>
<div class="col-sm-4">
<button (click)="settings()" class="pull-right button settingEnv">
<img src="/assets/images/E_Setting.png" class="newrun_btn" /> SETTINGS
</button>
</div>
<div class="col-sm-2">
</div>
</div>
<div>
<br>
</div>
</div>
</div>
</div>
<div class="col-sm-2"></div>
</div>

Develop login page using angularjs2 with validation

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">
Forgot password?
</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.
Change
form: FormGroup;
to
loginForm: FormGroup; //change here
it should work