I have a question about angular js 2. Who can talk to me how to receive data from input and return json string?
This's my code: http-test.component.ts
<form action="POST">
UserName
<div>
<input type="text" required id= "username"/>
</div>
Password
<div>
<input type="password" required id= "password" />
</div>
Name
<div>
<input type="text" required id= "name"/>
</div>
<div>
<button type ="submit"> Submit</button>
</div>
</form>
`,
styles:[`
table tr:nth-child(even) {
background-color: #eeeeee;
}
`],
providers: [HttpTestService]
})
customers: Object;
constructor( private _httpService:HttpTestService){}
//Return Object json
onTestTable(){
this._httpService.getCurrentTime()
.subscribe(
customers => this.customers = customers.records
);
//On init when load page
ngOnInit(){
this.onTestTable();
}
}
This's code Service: http-test.service.ts
constructor(private _http: Http) { }
getCurrentTime() {
return this._http.get('http://www.w3schools.com/angular/customers.php')
.map(res => res.json())
}
postJson(){
}
I want to receive data from input and return json string then post that json string to service when I press Submit. How can I do?
Thanks for reading!