How to get response data from golang backend via @ angular / http?
Selected typescript code:
signIn(signInCredential: SignInCredential): Promise<any> {
//Build the form package
let queryParam:string = 'principal=' + encodeURIComponent(signInCredential.principal) +
'&password=' + encodeURIComponent(signInCredential.password);
//Trigger Http
return this.http.post(signInUrl, queryParam, { headers: this.formHeaders })
.toPromise()
.then(() => null)
.catch(error => this.handleError(error));
}
Golang backend code:
func (cc *CommonController) Login() []byte {
group := ColorGroup{
ID: 1,
Name: "Reds",
Colors: []string{"Crimson", "Red", "Ruby", "Maroon"},
}
data, err := json.Marshal(group)
if err != nil {
fmt.Println("error:", err)
}
return data
}
Angular router:
beego.Router("/login", &controllers.CommonController{}, "post:Login")
How can I get the data returned by Login () in http.post typescipt?
Thanks for the answer!
+3
source to share
No one has answered this question yet
Check out similar questions: