从控制器angularjs传递多个参数恢复到出厂 [英] Passing multiple parameters from controller to factory in angularjs

查看:138
本文介绍了从控制器angularjs传递多个参数恢复到出厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从我的控制器传递三个参数到工厂下面的方式。

I am passing three parameters from my controller to the factory following way.

在我的控制器,我试图通过三个参数ID,SDT和EDT。

In my controller I am trying to pass three parameters id,sdt and 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}})
    };
}]);

当我运行此我得到错误的请求错误。请让我知道如何传递多个参数。谢谢

When I run this I get Bad Request error. Please let me know how to pass multiple parameters. Thanks

推荐答案

这工作得很好,你想presuming :ID 在你的查询字符串被替换 $ scope.id 的价值,以及两个查询参数( SDT EDT

This works fine, presuming you want :id in your query string to be replaced with the value of $scope.id, and two query parameters (sdt and edt) attached like:

http://www.example.com/api/Tech/GetRange/123?edt=20140610&sdt=20140609

好像你可以改为期望,看起来像一个网址:

It seems like you may instead be expecting a URL that looks like:

http://www.example.com/api/Tech/GetRange/123?end=20140610&start=20140609

...在这种情况下,你的code应该是这样的:

... in which case, your code should look like:

// 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}})
    };
}]);

演示

这篇关于从控制器angularjs传递多个参数恢复到出厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆