【问题标题】:Restangular POST form data in json format in Angular JSAngular JS中json格式的Restangular POST表单数据
【发布时间】:2013-09-03 05:50:54
【问题描述】:

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

我的索引页面:

<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 格式传递.....如果代码有误,请纠正我.....

【问题讨论】:

    标签: json rest angularjs restangular


    【解决方案1】:

    Restangular 中的帖子应该针对集合而不是元素。

    在你的情况下,POST应该是这样的;

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

    然后发出类似的POST请求;

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

    参考;

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 2018-01-25
      • 1970-01-01
      • 2013-07-07
      • 1970-01-01
      • 2015-01-01
      • 2012-07-26
      相关资源
      最近更新 更多