【问题标题】:token from cookie angular js来自cookie angular js的令牌
【发布时间】:2018-08-12 20:21:35
【问题描述】:
getToken() {

let res={};
let token = this.cookiesServices.getCookie("mobilecookie");
if(token){
   res.token=token;
  console.log("token-res",res);
  return res;
}else{
  return new this.httpUtils.POST(`${this.apiUrl2}authorization/token`);
}

getStoresCategories(mallId) { const res = this.getToken();

const defferd = this.$q.defer();
return res.then(dta => {
  const { token } = dta;
  const url = `${this.apiUrl2}stores/mall/${mallId}`;
  const conf = {
    headers: {
      Authorization: `bearer ${token}`,
      "Content-Type": "application/json",
      "Access-Control-Allow-Origin": "*"
    }
  };
  this.$http.get(url, conf).then(rsp => {
    defferd.resolve(rsp.data.data);
  });
  return defferd.promise;
});

}

缓存错误 TypeError: res.then 不是函数

【问题讨论】:

    标签: angularjs cookies token


    【解决方案1】:

    问题是res不是Promise,你应该使用$q.resolve把它转换成Promise

    【讨论】:

      猜你喜欢
      • 2023-03-12
      • 2018-09-01
      • 2021-12-18
      • 1970-01-01
      • 2016-12-29
      • 2015-05-28
      • 1970-01-01
      • 2022-01-13
      • 2018-02-19
      相关资源
      最近更新 更多