如何通过@ angular / http从golang后端获取响应数据?

时间:2017-07-13 02:42:00

标签: angular http typescript go beego

前面的打字稿代码是:

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代码是:

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
}

角度路由器是:

beego.Router("/login", &controllers.CommonController{}, "post:Login")

如何在typescipt的http.post中获取Login()返回的数据?

感谢所有回复!

0 个答案:

没有答案