Angular bad config Error: [$resource:badcfg] query
Angular bad config Error: [$resource:badcfg] query
我正在尝试将 spotify api 与节点 js 连接,并且 angular js.I 每当我尝试获取特定艺术家的详细信息时都会收到此错误。
app.js
var app = angular.module('angularjs-starter', ['jsonService', 'ngRoute', 'ngResource'])
app.controller('MainCtrl', function($scope, JsonService) {
//JsonService.get(function(data) {
// $scope.name = data.artists.href;
// $scope.children = data.artists.items;
//});
$scope.searchShow = () => {
JsonService.search.query({
show: $scope.showname
}, (response) => {
console.log(response);
// $scope.name = response.artists.href;
$scope.childr = response;
$scope.children = response;
})
}
$scope.showDetails = (id) => {
console.log(id);
JsonService.detail.query({
details: id
}, (response) => {
console.log(response);
// $scope.name = response.artists.href;
})
}
});
app.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('')
}])
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/search.html',
controller: 'MainCtrl'
})
.when('/details', {
templateUrl: 'views/details.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
})
}])
service.js
angular.module('jsonService', ['ngResource'])
.factory('JsonService', function($resource) {
return {
search: $resource('/api/search'),
detail: $resource('/api/details')
}
});
routes.js-来自节点js服务器
const
express = require('express'),
path = require('path'),
router = express.Router(),
superagent = require('superagent')
module.exports = () => {
router.get('/api/search', (req, res) => {
const { show } = req.query // this is the same as const show = req.query.show
console.log(show);
superagent
.get('https://api.spotify.com/v1/search?q=' + show + ':&type=artist')
.end((err, response) => {
if (err) {
res.send(err);
console.log(err);
} else {
console.log(response.body.artists.items);
res.json(response.body.artists.items);
}
})
})
router.get('/api/details', (req, res) => {
const { details } = req.query // this is the same as const show = req.query.show
console.log(details);
superagent
.get('https://api.spotify.com/v1/artists/' + details)
.end((err, response) => {
if (err) {
res.send(err);
console.log(err);
} else {
res.json(response.body);
}
})
})
router.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../client/index.html'))
})
return router
}
Node js 能够从详细信息中获取值,但我无法获取 ui
的值
当APIreturns单个对象时,使用get
动作方法:
$scope.showDetails = (id) => {
console.log(id);
//JsonService.detail.query({
//USE get action method
JsonService.detail.get({
details: id
}, (response) => {
console.log(response);
// $scope.name = response.artists.href;
})
}
当APIreturns数组时,使用query
动作方法。
Error: $resource:badcfg
Response does not match configured parameter
Description
This error occurs when the $resource service expects a response that can be deserialized as an array but receives an object, or vice versa. By default, all resource actions expect objects, except query
which expects arrays.
To resolve this error, make sure your $resource configuration matches the actual format of the data returned from the server.
For more information, see the $resource API reference documentation.
我正在尝试将 spotify api 与节点 js 连接,并且 angular js.I 每当我尝试获取特定艺术家的详细信息时都会收到此错误。
app.js
var app = angular.module('angularjs-starter', ['jsonService', 'ngRoute', 'ngResource'])
app.controller('MainCtrl', function($scope, JsonService) {
//JsonService.get(function(data) {
// $scope.name = data.artists.href;
// $scope.children = data.artists.items;
//});
$scope.searchShow = () => {
JsonService.search.query({
show: $scope.showname
}, (response) => {
console.log(response);
// $scope.name = response.artists.href;
$scope.childr = response;
$scope.children = response;
})
}
$scope.showDetails = (id) => {
console.log(id);
JsonService.detail.query({
details: id
}, (response) => {
console.log(response);
// $scope.name = response.artists.href;
})
}
});
app.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('')
}])
app.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/search.html',
controller: 'MainCtrl'
})
.when('/details', {
templateUrl: 'views/details.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
})
}])
service.js
angular.module('jsonService', ['ngResource'])
.factory('JsonService', function($resource) {
return {
search: $resource('/api/search'),
detail: $resource('/api/details')
}
});
routes.js-来自节点js服务器
const
express = require('express'),
path = require('path'),
router = express.Router(),
superagent = require('superagent')
module.exports = () => {
router.get('/api/search', (req, res) => {
const { show } = req.query // this is the same as const show = req.query.show
console.log(show);
superagent
.get('https://api.spotify.com/v1/search?q=' + show + ':&type=artist')
.end((err, response) => {
if (err) {
res.send(err);
console.log(err);
} else {
console.log(response.body.artists.items);
res.json(response.body.artists.items);
}
})
})
router.get('/api/details', (req, res) => {
const { details } = req.query // this is the same as const show = req.query.show
console.log(details);
superagent
.get('https://api.spotify.com/v1/artists/' + details)
.end((err, response) => {
if (err) {
res.send(err);
console.log(err);
} else {
res.json(response.body);
}
})
})
router.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../client/index.html'))
})
return router
}
Node js 能够从详细信息中获取值,但我无法获取 ui
的值当APIreturns单个对象时,使用get
动作方法:
$scope.showDetails = (id) => {
console.log(id);
//JsonService.detail.query({
//USE get action method
JsonService.detail.get({
details: id
}, (response) => {
console.log(response);
// $scope.name = response.artists.href;
})
}
当APIreturns数组时,使用query
动作方法。
Error:
$resource:badcfg
Response does not match configured parameter
Description
This error occurs when the $resource service expects a response that can be deserialized as an array but receives an object, or vice versa. By default, all resource actions expect objects, except
query
which expects arrays.To resolve this error, make sure your $resource configuration matches the actual format of the data returned from the server.
For more information, see the $resource API reference documentation.