正如我的标题所说我遇到的问题是我无法使用$ resource get方法正确返回数据。在我的chrome浏览器中,我只看到[object Object]的数据,但响应正确地显示了“success”字符串。所以我正在返回我无法使用它的数据!如果我将它更改为没有参数的查询并调用另一个返回列表的web api方法,它可以正常工作。就在我试图获得单一记录的时候。任何帮助将不胜感激。
编辑:AngularJS v1.3.0-rc.5 Edit2:在控制台中看起来像是一个数组 资源{0:“S”,1:“你”,2:“c”,3:“c”,4:“e”,5:“s”,6:“s”,$ promise:承诺, $ resolved:true,toJSON:function,$ get:function,$ save:function ...}
app.controller('fooController', function ($scope, fooService) {
$scope.person = function (person) {
fooService.get({ firstName: person.firstName, lastName: person.lastName })
.$promise.then(function (data) {
$scope.person.exist = data;
});
}
});
app.factory('fooService', function ($resource) {
return $resource('http://****.com/api/values/:lastName/:firstName', {
get: { method: 'GET', isArray: false}
});
});
//web api get
public string Get(string firstName, string lastName)
{
return "Success";
}