我们可以在angular JS的services promise中通过form加载本地json文件吗?
Can we load the local json file via form in angular JS services promise?
我试图通过表单填充我的json文件。javascript不会抛出任何错误,但是数据不会加载到json文件中。我现在还不习惯承诺。我可以看到一些从json文件中获取值的帖子,但反之亦然。有人能帮忙吗?
服务:
var module=angular.module('app',[]);
module.factory('memberDataStoreService',function($http)
{
var memberDataStore = {};
memberDataStore.addUser=function(adata){
var promise=$http({
method: 'POST',
url: 'data.json',
data: adata});
return promise;
}
return memberDataStore;
});
控制器
if ($scope.registrationForm.$valid) {
$scope.working = true;
var promise = memberDataStoreService.addUser($scope.person);
promise.success(function () {
$scope.showSuccessMessage = true;
});
promise.error(function (data, status) {
$scope.showErrorMessage = true;
});
promise.finally(function () {
$scope.working = false;
});
$scope.doShow = true;
}