Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Both pages are Shown up Angular

i am creating a login form using Angular.when i login the system it will login successfully when it is redirect to another page it need to shown up the home page details but it will shown up both login and home page details.what i tried so far i attached below.

email: string = '';
  password: string = '';
  
  isLogin: boolean = true;

  erroMessage: string = "";


  constructor(private router: Router,private http: HttpClient) {}
  login() {
    console.log(this.email);
    console.log(this.password);

    let bodyData = {
      email: this.email,
      password: this.password,
    };

        this.http.post("http://localhost:9002/user/login", bodyData).subscribe(  (resultData: any) => {
        console.log(resultData);

        if (resultData.status) 
        {
           alert("Sucess");
           this.router.navigate(['/home']);
           this.isLogin = false;

        } 
        else
         {
          alert("Incorrect Email or Password");
          console.log("Errror login");
        }
      });
    }
}

Routes

const routes: Routes = [

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  {
    path: 'login',
    component: LoginComponent
  },
  {
  path: 'home',
  component: HomeComponent,
  
  }


];

LoginComponent

<form>
    <div class="form-group">
      <label for="exampleInputEmail1">Email address</label>
      <input type="text" [(ngModel)]="email" [ngModelOptions]="{standalone: true}" class="form-control" id="stname" placeholder="Enter Email"/>
    </div>
    <div class="form-group">
      <label for="exampleInputPassword1">Password</label>
      <input type="password" [(ngModel)]="password" [ngModelOptions]="{standalone: true}" class="form-control" id="stname" placeholder="Enter Password"/>
    </div>
    <button type="submit" class="btn btn-primary" (click)="login()">Login</button>
  </form>

>Solution :

try defining a base path four your routing like :

{ path: '', component: HomepageComponent }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading