Written my code in angular cli with the help of sublime text editor and node.js  

my login component looks like logincomponent.ts

```
import { Component,OnInit } from '@angular/core';
import { FormsModule,NgForm } from '@angular/forms';
import {Router,ActivatedRoute} from '@angular/router';
import { AuthenticateService } from '../services/authenticate.service';
import { Login } from './login-model';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})

export class LoginComponent implements OnInit {     
    log:any={}; 
    data:any;
    res:any;

  constructor(private route:ActivatedRoute,private router:Router,private authenticate:AuthenticateService ) { 
   this.log = new Login(this.log.username,this.log.password)
  }

  ngOnInit() {  

  }
  onClick(){ 
    console.log("clicked");      
    this.authenticate.loginvalidate (this.log).subscribe((res) =>{console.log(res);});
}
}

```

i got error when i try to post the data to the rest api its shows error like Error: Error [object][object]

```
//service.ts

import { Injectable } from '@angular/core';
import { Http, Headers, Response,RequestOptions,Jsonp} from '@angular/http';
import { Login } from '../login/login-model';

import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';

@Injectable()
export class AuthenticateService {
res:any;
constructor(private http: Http, private jsonp:Jsonp) { }

   loginvalidate(user){
    let url = 'http://localhost:9000/EzeeShipping_Java/userlogin';
    const body = JSON.stringify({username:user.username,password:user.password });

   let headers = new Headers({ 'Content-Type': 'application/json' });
   let options = new RequestOptions({ headers: headers }); 

    return this.http.post(url,body,options).map(res=>res.json());
 }
}

```

my rest service s running in a tomcat server  

i dont know y i didnt get a json data as a response
kindly help me out 

login.component.html

```
<div class="container">
    <div class="row">
        <div class="col-md-4">
        </div>
        <div class="col-md-4">
            <div class="form-area">  
        <form #userform="ngForm" (ngSubmit)="onClick(userform)" >
        <br style="clear:both">
                    <h3 style="margin-bottom: 25px; text-align: center;">Login Form</h3>
                    <div class="form-group">
                        <input type="text" class="form-control" id="username" name="username" placeholder="Username" required [(ngModel)]="log.username" >

                    </div>

                    <div class="form-group">
                        <input type="Password" class="form-control" id="pwd" name="password" placeholder="Password" required [(ngModel)]="log.password">
                    </div>

        <button type="submit" id="submit" name="submit" class="btn btn-primary pull-right" [disabled]="userform.invalid">Login</button>
        </form>
    </div>
        </div>
        <div class="col-md-4">
        </div>
    </div>
    <div><button class="btn btn-primary" type="submit" (click)="test()">Test</button></div>
</div>

```

this is my login.component.html file

Login-model.ts

```
export class Login{
    public username:string;
    public password:string;

    constructor(u:string,p:string){
    this.username = u;
    this.password = p;

    }

}

```