NgCordova write file error

I am making an app using Ionic framework. I have used ngcordova angular library.

I have a zip folder which we are unzipping and then reading / writing the file.

When I am updating (write operation) on any file in "non rooted" phones, we are getting NO_MODIFICATION_ALLOWED_ERR. But this works fine in a "rooted" phone.

This issue is with write operation only. It is working fine while reading any file.

Please have a look at the code.

UpdateConfiguration: function (appconfig) {
        var defer = $q.defer();

        $cordovaFile.checkFile(cordova.file.dataDirectory, "Stock/database/appconfig.json").then(function (success) {

            $cordovaFile.writeFile(cordova.file.dataDirectory, 'Stock/database/appconfig.json', JSON.stringify(appconfig), true)
            .then(function (success) {
                defer.resolve(true);
            }, function (err) {
                alert(JSON.stringify(err));
                defer.reject(false);
            });

        }, function (error) {
            alert('Error finding app config file');
        });
        return defer.promise;
    }

Please help.

Thanks in advance.