javascript - After post response reload data in angularjs -
question after post data have small html table shows data data doesn't show until reload page getting automatically show data after submit appreciated.
here 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 need here reload 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 shows if manual page realod [
dim.save
asynchronous when call $scope.dims.push(dim)
, dim
not yet saved
the solution use success callback of promise
$scope.adddim = function () { dim.save($scope.newdim).$promise.then(function(dim) { $scope.dims.push(dim); $scope.newdim = {}; }); }
Comments
Post a Comment