Angular JS中json格式的Restangular POST表单数据 [英] Restangular POST form data in json format in Angular JS

查看:161
本文介绍了Angular JS中json格式的Restangular POST表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Angular JS的新手,我需要使用json格式的表单数据的restangular POST.我也是POST功能的新手,谁能告诉我该怎么做??

I am new to Angular JS and I am in a need to use restangular POST of form data in json format. Also I am new to the POST functionalities, can anyone tell me how I can do it??

我的索引页面:

<form ng-controller="registerCtrl">
 <input placeholder="Username" type="email" name="username"  ng-model="user.email" />
 <input placeholder="Password" type="password" name="password" ng-model="user.password"/>
 <input placeholder="Confirm Password" type="password" name="confirmpassword"  ng-model="user.confirmPassword" />
 <button class="btn btn-info" ng-click="registerUser()" type="submit">Login</button>
</form>

控制器

var myApp=angular.module('myApp',['restangular']);
function registerCtrl($scope, Restangular){
$scope.user = {};
$scope.registerUser=function(){
        $scope.people = Restangular.all('data.json/:user').post($scope.user);
    }
}

我应该在哪里将输入值作为Json格式传递......如果代码有误,请纠正我.....

Here where should I pass the input values as the Json format..... If am wrong with the code, pls correct me.....

推荐答案

Restangular中,帖子应放在集合而不是元素上.

In Restangular posts should be done to collections not elements.

在您的情况下,POST应该这样进行;

In your case POST should be made like this;

$scope.user = {email :"", password: "", confpass: ""};

然后发出POST请求,例如;

Then make POST request like;

Restangular.all('data.json/:user').post("users", $scope.user);

参考;

https://github.com/mgonto/restangular#element-methods

这篇关于Angular JS中json格式的Restangular POST表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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