import { Component } from "@angular/core" ; import { MyHttpPostService } from "./http-post.services" ; @ Component ( { moduleId : module . id , templateUrl : "./http-post.component.html" , providers : [ MyHttpPostService ] } ) export class HttpPostComponent { public user : string ; public pass : string ; public message : string = "" ; public isItemVisible : boolean = false ; constructor ( private myPostService ) { } public submit ( ) { this . makePostRequest ( ) ; } private makePostRequest ( ) { this . myPostService . postData ( { username : this . user , password : this . pass } ) . subscribe ( res => { this . message = ( < any > res ) . json . data . username ; this . isItemVisible = true ; } ) ; } }