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

前端 未结 5 937
旧时难觅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:11

    Phew, I was looking for this answer for so long, but it's good it is here. Just to update it, since legacy promise methods success and error have been deprecated and we should use the standard then method instead.

    Solution 2 in @geniuscarrier and @jim-horng answers may be rewritten like this:

    $http.get('/plugin/' + key + '/js').then(
        (function(key) {
            return function(data) {
                console.log(key, data);
            }
        })(key),
        function(data) {
            //error handle
        });
    

提交回复
热议问题