2

Is there a way in angularJS to write data to file in local folder? I managed to get data from the file and now i want to write something.

I get data from data.json, but order.txt is 404 (Not Found) or 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;
        });
    }
});  
2
  • I think this is not possible. Some alternatives suggested here: stackoverflow.com/questions/30288087/… Commented Feb 11, 2019 at 11:18
  • 1
    That makes sens. Thanks for the link. Commented Feb 11, 2019 at 11:24

1 Answer 1

1

You can try it by using **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));

Kindly go through that too.

Hope it helps. Thanks!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.