Angular $ http.get没有传递参数

Cac*_*eli 2 javascript spotify node.js express angularjs

这似乎是一个简单的问题,我必须忽略一些小事.

我有一个访问Spotify API并搜索艺术家的功能.我知道通过普通URL访问此路由会返回结果.(例如http://localhost:3001/search?artist=%27Linkin%20Park%27)这里的代码:

router.get('/search', function(req, res, next)
{
    var artist = req.param('artist');
    console.log("Artist: " + artist);
    smartSpot.getArtistID(artist, function(data)
    {
        console.log("Data: " + data);
        res.json(data.id);
    });
});
Run Code Online (Sandbox Code Playgroud)

然后,前端有代码搜索艺术家.这都是通过角度完成的.

angular.module('smart-spot', [])
    .controller('MainCtrl', [
        '$scope', '$http',
        function($scope, $http)
        {
            $scope.createPlaylist = function()
            {
                var artist = $scope.artist;
                console.log(artist);
                window.open("/login", "Playlist Creation", 'WIDTH=400, HEIGHT=500');
                return $http.get('/search?=' + $scope.artist) //this doesn't pass in the artist
                    .success(function(data)
                    {
                        console.log(data);
                    });

            }
        }
    ]);
Run Code Online (Sandbox Code Playgroud)

$http.get()不会在$ scope.artist`值传递正确.

Alb*_*rly 5

看起来您可能在字符串连接中缺少"artist"查询参数.

$http.get('/search?artist=' + $scope.artist)
Run Code Online (Sandbox Code Playgroud)

或者,您可以将艺术家作为查询参数传递.

function createPlaylist() {
    return $http.get('/search', { params : { artist : $scope.artist } })
    .then(function(response) {
        return response;
    }, function(error) {
        return $q.reject(error);
    });
}   
Run Code Online (Sandbox Code Playgroud)

另外,我会避免使用.success.我认为这有利于上面的语法.第一个参数是成功函数,第二个是失败函数.