【发布时间】:2017-02-07 04:27:07
【问题描述】:
我找不到错误。我的 php 文件返回 ["9963648941","7416527247"] 之类的数据,我正在使用 angular factory 使用 http 调用获取数据,如下所示
app.factory("States", function ($http){
var mData = {
getStates: function(){
return $http.get('php/usersList.php')
}
};
return mData;
});
States工厂在控制器中使用如下
app.controller('orderFormController', function($scope,$location,$rootScope,$http,States)
{
States.getStates.then(function(response){
console.log(JOSN.parse(response.data));
})
});
最后我收到错误,因为 States.getStates.then 不是控制器中的函数。
【问题讨论】:
-
console.log(JOSN.parse(response.data));它的“JSON.parse”
-
不是您当前的问题,但默认情况下 Angular 将解析
response.data属性中的 JSON。你不需要再做一次