Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在ngResource post URL中使用参数_Angularjs_Rest_Fosrestbundle_Ngresource - Fatal编程技术网

Angularjs 在ngResource post URL中使用参数

Angularjs 在ngResource post URL中使用参数,angularjs,rest,fosrestbundle,ngresource,Angularjs,Rest,Fosrestbundle,Ngresource,我正在使用FosRestBundle API,必须在url post资源中传递参数才能执行操作 FosrestBundle中的post资源如下所示: api/readQuestion/{contain_id}/{user_id}/{type_id}/Questions question.postQuestion(newQuestion, 1 ,1 ,1 ), 因此,在我的angularjs应用程序中使用该资源发送数据。我创建了一个服务,并以这种方式执行: angular.module("Q

我正在使用FosRestBundle API,必须在url post资源中传递参数才能执行操作

FosrestBundle中的post资源如下所示:

api/readQuestion/{contain_id}/{user_id}/{type_id}/Questions
question.postQuestion(newQuestion, 1 ,1 ,1 ), 
因此,在我的angularjs应用程序中使用该资源发送数据。我创建了一个服务,并以这种方式执行:

angular.module("QuestionRest", ['ngResource'])

.factory("question",  function ( $resource) {


    var apiData = $resource(
        "/api", {},
        {
            "postQuestion" : { method: "POST", url: "/api/readQuestion/:containid/:userid/:typeid/Questions"}
        });

    return {

        postQuestion: function(newQuestion, contain_id, user_id, type_id) {
            apiData.postQuestion(newQuestion, {containid: contain_id, userid: user_id, typeid: type_id}, function() {
                console.log("Success !");
            }, function(error) {
                console.log("Error " + error.status + " when sending request : " + error.data);
            });

        }

    }
});
但它根本不起作用。当我在我的应用程序控制器中调用postQuestion时,如下所示:

api/readQuestion/{contain_id}/{user_id}/{type_id}/Questions
question.postQuestion(newQuestion, 1 ,1 ,1 ), 
我得到了这个错误:

angular.js:12410 POST http://localhost:8000/api/readQuestion/Questions?description=%3Cp%3Efdfdf%3C%2Fp%3E&title=fdf%3F&line=1000&page=1000 404 (Not Found)
其中:

{
"title": "fdf?",
"description": "Cp...3Efdfdf...",
"line": "1000",
"page": "1000"
 }
是我的post请求发送的newQuestion JSON对象

你知道我的意思


在angular app post URL中传递参数的最佳方式是什么?

参数和数据是反向的:

可以使用以下参数调用类对象或实例对象上的操作方法:

  • 非获取“类”操作:Resource.action([parameters]、postData、[success]、[error])

错误消息的确切措辞是什么,是哪行代码产生的?