"use strict"; | |
angular.module("martVisualEnrichment.services", []) | |
.factory("results", | |
["$document", "$q", "enrichmentResultsId", | |
function resultsFactory ($doc, $q, containerId) { | |
// I'm using a promise such that if we get data with ajax the API won't | |
// change. | |
var deffed = $q.defer(), | |
elm = $doc.getElementById(containerId), | |
value = null, error = null; | |
try { | |
if (elm) { | |
value = JSON.parse(elm.textContet); | |
deffed.resolve(value); | |
} else { | |
error = "Cannot find element with id `"+containerId+"`" | |
} | |
} catch (err) { | |
error = err.name + ": " + err.message; | |
} | |
error ? deffed.reject(error) : deffed.resolve(value); | |
return deffed.promise; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment