UIでファイルのアップロードの成功または失敗にメッセージを表示する。 私は次のファイル構造を持っています。angularJSのサービスからスコープ変数を使用する方法
コントローラー:
$scope.uploadFile = function() {
//using a service
fileUpload.uploadFileToUrl(file, uploadUrl)
};
これは完全に正常に動作します:
マイファイルのアップロード機能は、このようなものです。 ファイルアップロードサービスは、次のようになります。
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() {
});
}
}]);
どのように私の代わりにアラートを使用しての私のhtmlページにメッセージを表示することができます。私は変数varメッセージを設定しようとしました。それをサービスから戻しますが、無限ループに陥ってしまいました。スコープ変数を使用しようとしましたが、その変数も無限ループに入ります。応答が利用可能になったとき
ヘルプ
この投稿で受け入れられる回答を見てください。https://stackoverflow.com/questions/28382927/listen-to-window-events-in-an-angularjs-service質問はあなたと同じではありませんでしたが解決策あなたのために働くでしょう。 – jbrown