get方法是AbstractRestfulController类,如下所示:
public function get($id)
{
$user = $this->userModelService->getUserRepository()->find($id);
if (!$user) {
return new JsonModel(['message' => 'No user with this ID']);
}
return new JsonModel([
'user' => $user,
]);
}
并且AngularJS控制器是:
apiApp.controller('getCtrl', function getCtrl($scope, $http)
{
var getc = this;
getc.finalUrl = "";
getc.mainUri = "";
getc.sendRequest = function sendRequest(mainUrl, userId)
{
getc.finalUrl = 'http://user.local/user/api/1';
//mainUrl + '/' + userId;
$http.get({
url: 'http://user.local/user/api/1',
method: 'GET',
// params: {"id": userId}
})
.then( function onSuccess(responce){
getc.msgData = responce.data;
getc.msgConfig = responce.config;
getc.msgHeaders = responce.headers;
} , function onError(responce){
getc.msg = responce.statusText;
} );
};
});
我已经通过命令行测试了API,并且得到了结果。
但是从AngularJS的角度来看,我收到了$http:badreq错误!
[请您帮我找出这段代码有什么问题吗?
当传递到$ http服务的请求配置参数不是有效的对象时,会发生此错误。 $http
需要一个参数,即请求配置对象,但接收到的参数不是对象或不包含有效属性。
错误消息应提供其他上下文,例如接收到的参数的实际值。
̶$̶h̶t̶t̶p̶.̶g̶e̶t̶(̶{̶
$http({
url: 'http://user.local/user/api/1',
method: 'GET',
// params: {"id": userId}
})