如何使用angularjs使用$ resource发布数据

时间:2013-08-19 02:52:53

标签: codeigniter angularjs

我有一点问题,我试图向我的后端php发送一个http post请求。我是angular的新手,想尝试不同的REST方法。我对GET方法很满意。在此之后,我将尝试UPDATE和DELETE方法,但现在我仍然坚持这一点。 T__T。

这里有一些php中的代码

$data = array(
        "email" => $email,
        "password" => $this->input->post("password")
    );
$insert_data = $this->player_registration->insert($data);

这是我的工厂

angular.module('myApp.services', ['ngResource'])
.factory('webService', function($resource){
var apiUrl = "http:domain.com/feed/"; //change this to web service
var factory = {};

factory.registerPlayer = function() {
    return $resource( apiUrl + ':type', {type:'player'}, {
        post: {method:'POST', params: {}}
    });
};

factory.getPlayerByEmail = function () {
    return $resource( apiUrl + ':type', {type:'player'}, {
        get: {method: "GET", params: {}}
    });
};
return factory;
})

我的控制器

function registerController($scope, webService) {
$scope.inputs = {};
$scope.inputs.email = "testuser@domain.com";
$scope.inputs.password = "password";

var req = new webService.registerPlayer($scope.inputs);
req.save()

我的app.js

angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', 'myApp.controllers'])

1 个答案:

答案 0 :(得分:0)

$ resources中的默认save()实际上是$save()

var req = new webService.registerPlayer($scope.inputs);
req.$save()