AngularJS-在承诺之间共享返回值

时间:2018-09-19 15:11:38

标签: angularjs http get

我正在向服务器发出获取请求,得到响应并将值存储在 $ scope.productId

  userService.get(true)
    .then(function(res) {
      $scope.productId = res.user.productid;
      }
    });

然后,我需要在对API的另一个获取请求中使用该值,以获取与此ID相关的产品。

  apiService.get('/product/' + ???)

  .then(function(response) {
    console.log(response)
  })

  .catch(function(response) {
  });

我对Promise并不陌生,所以目标是将第一个请求的值转化为第二个请求!

1 个答案:

答案 0 :(得分:1)

使用此

$(document).ready(function () {

     $('#sidebarCollapse').on('click', function () {
         $('#sidebar').toggleClass('active');
         $('.overlay').addClass('active');
         $(this).toggleClass('active');
     });

     $('.overlay').on('click', function () {
        $('#sidebar').removeClass('active');
        $('.overlay').removeClass('active');
        $(this).removeClass('active');

     });
 });
相关问题