0

我遇到了一点问题,我正在尝试向我的后端 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'])
4

1 回答 1

0

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

var req = new webService.registerPlayer($scope.inputs);
req.$save()
于 2013-08-19T03:11:08.280 回答