我想在cookie中添加一个令牌唯一的问题,并且在获得API的响应之前创建了cookie,我可以做些什么来等待响应然后创建cookie?
我的代码
getlogin()
{
this._symfonyservice.login(this.user,this.pass).subscribe(//call the post
data => this.results = data, // put the data returned from the server in our variable
error => console.log("Error HTTP Post Service"), // in case of failure show this message
() => console.log(this.results['token'])//run this code in all cases
);
if(this.results['token']!="")
{
let token = this.results['token'];
this.deleteCookie("Cookieteste");
this.setCookie("Cookieteste",token, 1);
}
}
答案 0 :(得分:1)
在data
而不是() final function
getlogin()
{
this._symfonyservice.login(this.user,this.pass).subscribe(//call the post
data => {
this.results = data
if(this.results['token']!="")
{
let token = this.results['token'];
this.deleteCookie("Cookieteste");
this.setCookie("Cookieteste",token, 1);
}
}, // put the data returned from the server in our variable
error => console.log("Error HTTP Post Service"), // in case of failure show this message
() => console.log('completed')//run this code in all cases
);