I want a message to be displayed on file upload success or failure on the UI. I have the following file structure.
Controller:
My file upload function is like this:
$scope.uploadFile = function () {
//using a service
fileUpload.uploadFileToUrl(file, uploadUrl)
};
This works perfectly fine. The fileUpload service looks like this:
angular.module('myApp').service('fileUpload', ['$http', function
($http) {
//upload function happens here and returns a promise, This is executing fine.
.success(function (response) {
if (response.status=="uploadSuccess")
{
alert("The file has been successfully uploaded");
var message = "success";
}
if (response.status == "uploadFailure") {
alert("The file could not be uploaded");
}
if (response.status == "uploadFailureExc") {
alert("The file could not be uploaded due to an exception that occured");
}
if (response.status == "FileExists") {
alert("The file could not be uploaded - a file with that name already exists");
}
})
.error(function () {
});
}
}]);
How can I display a message on my html page instead of using alerts. I have tried to set a variable var message. and then returning it out of the service, but its going in some infinity loop and getting stuck. I have tried to use a scope variable and its also going in some infinite loop.
Help