角JS获取和从静止框架数据集 [英] Angular js get and set data from rest framework
本文介绍了角JS获取和从静止框架数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个角的js服务写法如下:
I have an angular js service written as follows:
angular.module('jsonService', ['ngResource'])
.factory('ProgramsService',function($http) {
return {
getItems: function(callback) {
$http({method:'get', url:'/api/studentacademicprogram/?format=json'}).success(callback);
}
};
})
.factory('DegreesService', function($resource) {
return $resource('/static/json/degrees.json')
})
在我的app.js,我称这种服务如下:
In my app.js, i call this service as follows:
app.controller('mycontroller', function(DegreesService, DegreeCategoriesService, DetailsService, ProgramsService, $scope, $modal, $log, $http) {
ProgramsService.getItems(function(data){
$scope.programs = data;
console.log(data);
});
DegreesService.query(function(data){
$scope.degrees = data;
console.log(data);
});
有了这个code的帮助下,我能够得到JSON数据,并在我的前端体现出这一点。但我也想添加一些功能来更新,当我在前端addchanges连接到其他框架数据库。
With the help of this code i am able to get json data and reflect it in my front end. But i also would like to add some functionality to update the database that connects to the rest framework when i addchanges in the front end.
我如何做到这一点使用$ HTTP?
How do i do this using $http ?
推荐答案
创建接受HTTP帖子在服务器上的方法。然后做这样的事情:
Create a method on your server that accepts HTTP Posts. Then do something like this:
$http.post('/api/studentacademicprogram/', jsonDataToPost).then(function(){
//post succeeded
}, function() {
//post failed
});
这篇关于角JS获取和从静止框架数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文