3

The fronted typescript code is:

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));      
}

The backend golang code is:

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
}

The angular router is:

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

How can I get the data returned by the Login() in the http.post of typescipt?

Thanks for all reply!

卢焱鑫
  • 39
  • 3
  • 1
    You must register *response handler* in `then` function instead of `()=>null`. Take a look at [https://angular.io/guide/http#promises](https://angular.io/guide/http#promises). – putu Jul 13 '17 at 07:30
  • @putu Thanks for your guide! I have solved the problem. – 卢焱鑫 Jul 13 '17 at 11:17

0 Answers0