首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AngularJS如何制作一个JSON

AngularJS如何制作一个JSON
EN

Stack Overflow用户
提问于 2013-11-24 20:55:35
回答 1查看 97关注 0票数 0

我正在尝试发布一个帖子,但是下面的内容似乎不起作用,它不能发布,但是console.log()看起来像一个put请求。

代码语言:javascript
复制
http://127.0.0.1/api/v1/participant?account=%7B%22pk%22:1%7D&email=someemail@gmail.com

工厂

代码语言:javascript
复制
app.factory('CbgenRestangular', function(Restangular) {
    return Restangular.withConfig(function(RestangularConfigurer) {
        RestangularConfigurer.setBaseUrl('http://127.0.0.1');
    });
});

控制器

代码语言:javascript
复制
$scope.participant = {email :$scope.email, password: "", account:{pk:1}};
CbgenRestangular.all('api/v1/participant').post("participant", $scope.participant);

我做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-24 21:08:48

根据文档(https://github.com/mgonto/restangular#lets-code):

代码语言:javascript
复制
// First way of creating a Restangular object. Just saying the base URL 
var baseAccounts = Restangular.all('accounts');

var newAccount = {name: "Gonto's account"};

// POST /accounts 
baseAccounts.post(newAccount);

注意,post只有一个输入

您可以将'api/v1‘添加到您的基本地址--无需携带它(https://github.com/mgonto/restangular#setbaseurl)

我还建议使用复数形式的资源路线,但这是一个惯例,有些人不遵循-我想这是一个品味的问题

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20180880

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档