As i am trying to use promise to create html5 directory functions in angularjs. but it shows error as promise not defined.
Angular file:-
$scope.createDirectory = function(dirName,dirLocation){
fileManager.createDirectory(dirName,dirLocation)
.then(function(data){
console.log(data, "dir created");
}).fail(function(err){
console.log(err,"dir err while creating");
});
};
JS File:-
var fileManager = {
createDirectory: function(directoryName,dirLocation){
var makePromise = new Promise(function(resolve, reject){
dirLocation.getDirectory(directoryName, {create: true, exclusive: false}, function(data){
resolve(data);
}, function(error){
reject(error);
});
});
return makePromise;
}
}
TypeError: fileManager.createDirectory(...).then(...).fail is not a function
at h.$scope.createDirectory (app.js:60)
at angular.min.js:196
at f (angular.min.js:224)
at h.$eval (angular.min.js:123)
at h.$apply (angular.min.js:123)
at HTMLButtonElement.<anonymous> (angular.min.js:224)
at HTMLButtonElement.c (angular.min.js:32)
how to create promise properly and bind it to angular function. I've used catch instead of fail it worked. how to create custom error callback to all fail function like this