[英]After post response reload data in angularjs
Question after I post my data I have a small html table that shows my data however my data doesn't show until I reload the page any help getting this to automatically show my data after I submit will be greatly appreciated. 我发布数据后的问题我有一个小的html表,显示我的数据但是我的数据没有显示,直到我重新加载页面任何帮助,我提交后自动显示我的数据将非常感谢。
Here is my angular_stuff 这是我的angular_stuff
var dim = angular.module('Dim', ['ngResource']);
dim.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.xsrfCookieName = 'csrftoken';
$httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken';
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
}]);
dim.config(function ($interpolateProvider) {
$interpolateProvider.startSymbol('{[{');
$interpolateProvider.endSymbol('}]}');
});
dim.factory("Dim", function ($resource) {
return $resource("_dims.html", { pk: 'pk' }, {
index: { method: 'GET', isArray: true, responseType: 'json' },
update: { method: 'POST', responseType: 'json' },
delete: { method: 'DELETE', headers: { 'X_METHODOVERRIDE': 'DELETE' } },
});
})
dim.service('dataService', function () {
this.data = {}
this.data.dimMap = new Array();
this.data.dimMap[""] = "description";
});
//dim.controller("DimController", function($scope, $http, Dim) {
dim.controller("DimController", function ($scope, $http, Dim) {
$scope.dims = Dim.index()
//$scope.dims = dataService.data.dimMap;
$scope.addDim = function () {
dim = Dim.save($scope.newDim)
//My guess is I need something here to reload my data ???
$scope.dims.push(Dim)
$scope.newDim = {}
}
$scope.deleteDim = function (index) {
dim = $scope.dims[index]
Dim.delete(dim)
$scope.dims.splice(index, 1);
}
$scope.newField = {};
$scope.editDim = function (field) {
window.console.log($scope.dims[field]);
$scope.editing = $scope.dims.indexOf(field);
$scope.newField[$scope.editing] = angular.copy(field);
}
})
Data only shows up if I do a manual page realod [ 如果我做手册页实时数据,则仅显示数据[
Dim.save
is asynchronous so when you call $scope.dims.push(dim)
, dim
is not yet saved Dim.save
是异步的,所以当你调用$scope.dims.push(dim)
, dim
还没有保存
The solution is to use the success callback of the promise 解决方案是使用promise的成功回调
$scope.addDim = function () {
Dim.save($scope.newDim).$promise.then(function(dim) {
$scope.dims.push(dim);
$scope.newDim = {};
});
}
Add $scope.dims = Dim.index() at the end of $scope.addDim function. 在$ scope.addDim函数的末尾添加$ scope.dims = Dim.index() 。 It will make a call and you will get the data.
它将拨打电话,您将获得数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.