angular - Angular2 typescript POST request -


i'm testing sample: http://plnkr.co/edit/wtu5g9db3p4pkzs0wvw6?p=preview.

this code, implements login form name, mail, profile. on clicking submit button, alert appears on display name , email fields.

saveuser() {     if (this.userform.dirty && this.userform.valid) {         alert(`name: ${this.userform.value.name} email: ${this.userform.value.email}`);     } } 

on above, saveuser function in app.component.ts. executes alert on clicking button. on saveuser function, invoke post request. how can it?

you can save users calling service( using post request) in below sample.

var headers = new headers(); headers.append('content-type', 'application/json'); this.http.post('http://www.syntaxsuccess.com/poc-post/',                         json.stringify({firstname:'joe',lastname:'smith'}),                        {headers:headers}) .map((res: response) => res.json()) .subscribe((res:person) => this.postresponse = res); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -