我正在按照以下方式将三个参数从控制器传递到工厂。
在我的控制器中,我试图传递三个参数id,sdt和edt ..
$scope.val = function () {
$scope.tech = techRepository.getTech.query({ id: $scope.id, sdt: $scope.sDate, edt: $scope.eDate }, function(data) {
scope.tech = data;
});
};
在我的工厂里
App.factory('techRepository', ['$resource', function ($resource) {
return {
getTech: $resource('/api/Tech/GetRange/:id', {id: '@id', start: '@sdt', end: '@edt'}, {query: {method: 'GET', isArray:true}})
};
}]);
当我运行此程序时,我收到错误请求错误。请让我知道如何传递多个参数。谢谢
假设您希望:id
将查询字符串中的值替换为$scope.id
,并附加了两个查询参数(sdt
和edt
),效果很好,如下所示:
http://www.example.com/api/Tech/GetRange/123?edt=20140610&sdt=20140609
似乎您可能希望使用一个看起来像这样的URL:
http://www.example.com/api/Tech/GetRange/123?end=20140610&start=20140609
...在这种情况下,您的代码应如下所示:
// in controller
$scope.val = function () {
$scope.tech = techRepository.getTech.query({ id: $scope.id, start: $scope.sDate, end: $scope.eDate }, function(data) {
scope.tech = data;
});
};
.factory('techRepository', ['$resource', function ($resource) {
return {
getTech: $resource('/:id', {id: '@id'}, {query: {method: 'GET', isArray:true}})
};
}]);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句