angularJS中是否可以将数据写入本地文件夹中的文件?我设法从文件中获取数据,现在我想写点东西。
我从data.json
获取数据,但是order.txt
是404 (Not Found)
或ERR_CONNECTION_REFUSED
。
angular.module("sportsStore")
.constant("dataUrl", "data.json")
.constant("orderUrl", "order.txt")
.controller("sportsStoreCtrl", function ($scope, $http, $location,
dataUrl, orderUrl, cart) {
$scope.data = {
};
$http.get(dataUrl)
.success(function (data) {
$scope.data.products = data;
})
.error(function (error) {
$scope.data.error = error;
});
$scope.sendOrder = function (shippingDetails) {
var order = angular.copy(shippingDetails)
order.products = cart.getProducts();
$http.post(orderUrl, order)
.success(function (data) {
$scope.data.orderId = data.id;
})
.error(function (error) {
$scope.data.orderError = error;
});
}
});
答案 0 :(得分:1)
您可以使用**blob**
$scope.data = {
};
$scope.writeFile = function () {
$scope.data = angular.toJson($filter('filter')($scope.sendOrder));
};
}]);
var blob = new Blob([scope.writeFile],{
type: "application/json;charset=utf-8;"
});
downloadLink.attr('href', window.URL.createObjectURL(blob));
也请通过that。
希望有帮助。 谢谢!