How to pass a value to an AngularJS $http success callback

前端 未结 5 909
旧时难觅i
旧时难觅i 2020-12-31 04:54

In my AngularJS application I am doing the following

$http.get(\'/plugin/\' + key + \'/js\').success(function (data) {
    if (data.length > 0) {
                 


        
5条回答
  •  借酒劲吻你
    2020-12-31 05:06

    Instead of polluting scope or complicating with iif, another cleaner way is to create a callback function and call it with parameters;

    var myCallBack = function (key) {
      return function (data) {
        if (data.length > 0) {
          console.log(data, key);
        }
      }
    }
    
    $http.get('/plugin/' + key + '/js').success(myCallBack(key));
    

提交回复
热议问题