Javascript 未捕获引用错误:未定义cbfunc

Javascript 未捕获引用错误:未定义cbfunc,javascript,angularjs,Javascript,Angularjs,我现在有 “未捕获引用错误:未定义cbfunc” 我发展中的问题 .controller('PlaylistCtrl', function($scope, $stateParams, $http, httpGetData) { console.log($stateParams.catID); $scope.items = []; httpGetData.getTerkini().success(function(response){ $scope.items = response.rss.

我现在有

“未捕获引用错误:未定义cbfunc”

我发展中的问题

.controller('PlaylistCtrl', function($scope, $stateParams, $http, httpGetData) {

console.log($stateParams.catID);

$scope.items = [];

httpGetData.getTerkini().success(function(response){
$scope.items = response.rss.channel.item;

});     
}))


有人能帮我吗?thx

首先,您没有在工厂退回承诺。改为:

     return $http({

         method: 'JSONP',
         url:'http://json2jsonp.com/?callback=cbfunc&url=http%3A%2F%2Ffullcontentrss.com%2Ffeed.php%3Furl%3Dwww.bharian.com.my%252Fterkini.xml%26key%3D2%26hash%3D3b961c45997507e9d86fae68fa34a216ee866830%26max%3D10%26links%3Dpreserve%26exc%3D%26format%3Djson'

     }).then(function(response) { //promise here
           return response;
     })
其次,在api中,您为api响应声明了一个处理程序“cbfunc”,因此需要在控制器中定义它:

function cbfunc(response) {
    console.log(response);
}
现在看看你的代码。您的数据项是一个对象。因此,为了访问或调用getTerkini函数,您需要编写

httpGetData.dataItems.getTerkini()

但你能做的不是这样,而是

angular.module('starter.services', [])
.factory('httpGetData', function($http){
return {
 var dataItems = {};  // I don't understand the purpose of having dataItmes. basically what you can do is, you can use it within factory. but if you want to return it than your way would be cool.
 getTerkini = function(){
     return $http({
        ..... //function is going to return promise which can be caught at controller.
     });         
 }
});
所以,你可以这样称呼它


httpGetData.getTerkini()

我发现答案是将URL更改为标准JSONP格式,回调必须为callback=JSON\u callback

您好,我一直说我的回调“cbfunc”没有定义。我想您必须定义一个函数“cbfunc”来处理响应。我尝试了您的方法,但结果也一样,没有定义回调错误
angular.module('starter.services', [])

.factory('httpGetData', function($http){

 var dataItems = {};

 dataItems.getTerkini = function(){
     return $http({

         .....

     });         
 }
return dataItems;
angular.module('starter.services', [])
.factory('httpGetData', function($http){
return {
 var dataItems = {};  // I don't understand the purpose of having dataItmes. basically what you can do is, you can use it within factory. but if you want to return it than your way would be cool.
 getTerkini = function(){
     return $http({
        ..... //function is going to return promise which can be caught at controller.
     });         
 }
});