Skip to content

Instantly share code, notes, and snippets.

@lpand
Created February 27, 2014 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lpand/9249435 to your computer and use it in GitHub Desktop.
Save lpand/9249435 to your computer and use it in GitHub Desktop.
"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