2016-07-21 234 views
1

我目前正在研究一个Rails后端项目,我需要一些帮助来翻译这个curl命令。我们使用设计来允许用户登录,但我不确定如何将这个实现到AngularJS $ http请求中。

卷曲-v -H '内容类型:应用程序/ JSON' -H '接受:应用/ JSON的' -X POST http://localhost:3000/users -d

“{\” 用户\ “:{\” 电子邮件\ “:\” [email protected] \”,\ “密码\”:\ “密码\”}}”

回答

1
app.controller('LoginController', function($http){ 
    var user = {"user":{"email":"[email protected]","password":"password"}}; 

    $http.post('http://localhost:3000/users',user).then(function(result){ 
     // success. do something 
    }); 
}); 

,你很可能想要发布帖子请求,为此,请将$http服务注册到您的controllerservice你想要发送请求并用你的用户数据调用post到url,其中用户数据是一个json对象。