現在保守を担当しているプログラムでangularjsを利用しております。
非同期通信が正常に完了しない場合がある可能性がある為、
エラー処理とタイムアウト処理を入れたく存じます。
まず、以下にプログラムを記載します。
angularjs
1app.factory('AppModel', function(FavoriteApi, ProductApi) { 2 return { 3 〜 省略 〜 4 search: function(callback) { 5 var params; 6 params = this.searchParams; 7 params.PageNumber = this.pageNumber; 8 params.PerPage = this.perPage; 9 FavoriteApi.query(params, (function(_this) { 10 return function(u) { 11 if ((u.status == null) || u.status === false) { 12 alert(u.error); 13 return false; 14 } 15 _this.allCount = u.AllCount; 16 _this.pageNumber = u.PageNumber; 17 _this.perPage = u.PerPage; 18 _this.pageCount = Math.ceil(_this.allCount / _this.perPage); 19 _this.products = u.Product; 20 _this.products.map(function(product) { 21 product.second = false; 22 product.viewMemo = false; 23 product.CustomerModelNumberTemp = product.CustomerModelNumber; 24 product.MemoTemp = product.Memo; 25 product.CustomerModelNumberTemp = product.CustomerModelNumber; 26 if (product.favorite == null) { 27 product.favorite = false; 28 } 29 product.Cart = {}; 30 return product; 31 }); 32 _this.updateCache(); 33 if (callback != null) { 34 return callback(); 35 } 36 }; 37 })(this)); 38 return 1; 39 }, 40 }; 41}); 42 43app.factory('FavoriteApi', function($resource) { 44 return $resource("/api/favorite/:id", {}, { 45 query: { 46 method: 'GET', 47 isArray: false 48 }, 49 }); 50});
ご助言頂きたいのは、
1.favoriteApi.query()で第二引数の意味合いがわかりません。
正常に同期した場合に動いている様なのですが、
ググってもこの書き方の意味合いがわからず説明頂けるか参考サイト等ご教示頂ければ幸いです。
2.タイムアウトや500が返ってきた場合の処理方法。
ググって見たのですが、方法がわからずやり方ご教示してもらいたいです。
※公式HP見てtimeoutもnumberは設定出来ましたがpromiseの設定がわからず、その時の処理が入れられませんでした。。。
宜しくお願い致します。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。