【发布时间】:2015-12-18 23:32:33
【问题描述】:
我使用 Slim 框架构建了一个 API。
我在 Slim 中的一条路线接受可选参数。
有什么方法可以使用 angularjs $http.get 来做到这一点。如何在请求中设置可选参数。
下面是我的代码;
$scope.getRestaurant = function () {
return $http({
method: 'get',
url: "http://api.example.co.uk/web/restaurant/details/" + $scope.id + "/" + $scope.u,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
return response.data;
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
return [];
});
}
如您所见,我有$scope.id 和$scope.u。我希望$scope.u 是可选的。目前它总是通过,即使它为空。
【问题讨论】:
标签: javascript angularjs slim