javascript - angularjs handling $resource $promise errors -


Does anyone help me to recover hard-coded data in my fingers factory, if my API My hard-coded data are located in another factory named "Datafish", appreciate the help.

  service.factory ("'$ http', '$ resource', '$ q', 'datafactory', function ($ http, $ resource, $ Q, dataFactory ) {Var objFactory = {}; objFactory.getDaysOfWeek = function (include code) {var day = []; var API = $ resource (restURL + '/ daysOfWeek /'); API.query (). $ Promise. Function (data) {isEmpty = (data.length === 0); if (! IsEmpty) {days = data;};}). Key (function (error) {console.log ("Disapproved" + JSON.stringify (Error)); var data = faucet; day = datafreconditions of week; console.log (daytime label); // return 5}; console.log (+ day after "promise." Lamp); // return ' Promise 0 'return My datafactor is defined as follows:  
  dataApp.factory ("datafactory", function () {objDataFactory = { }; ObjDataFactory.daysOfWeek = [{DayName: 'Monday', debreviv: 'mon', index: 1, selected: incorrect, havic: true}, {day name: 'Tuesday', day Abrevy: 'lawsuit ', Index: 2, has been selected: wrong, awake: true}, {DayName:' Wednesday ', day abrevii:' Mercury ', index: 3, has been selected: is incorrect, hawk: true} {Days: 'Thursday', Day Abrevy: 'Guru', Index 4, have been selected: wrong, Hadivs: true}, {days: Friday, Dinabrbrv: 'Venus', Index 5, Hacli D: is false, is awake: true]]; Back to objDataFactory; });  

I think you want this:

 < Code> service.factory (['$ http', '$ resource', '$ q', 'datafactory', function ($ http, $ resource, $ q, datafactory) {var ObjFactory = {}; objFactory.getDaysOfWeek = Function (include) {var api = $ resource (restURL + '/ daysOfWeek /'), defObj = $ q.defer (); var daycode = API.query (); days. $ Commitment. Then (function (data) {// You can add any thing to this function defObj.resolve (data);}, function (error) {// You can add whatever you want in this function defObj.resolve (DataFactory. DaysOf Returning defObj.promise;}  

I left any data formatting and assignment details because you are liable to change them in any way. By wrapping in an additional promise you get the ability to manipulate what you have returned. If your API can be reached, then you can return its data in the resolution of your external promise. Otherwise, you will return your hard-code data from your second service in the solution of your external promise.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -