Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
An example of using a post request in a class, in Angular 2 (typescript) :
import {Http} from '@angular/http';
export class LoginPage {
public name : string;
public pass : string;
constructor(public http: Http) {
this.http = http //что бы вызывать через this.http, можно эту строку не писать и обращаться напрямую к Http
}
auth() {
let url = '/conf/post_admin.php';
let body = "username=" + this.name + "&password=" + this.pass;
//body должен быть строкой
this.http.post(url,body)
.subscribe(data => {
//где data - респонс от сервера
console.log(data)
});
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question