Created
January 18, 2014 03:41
-
-
Save dhigginbotham/8485859 to your computer and use it in GitHub Desktop.
Angular.js factory to load preload templates.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('$preload', ['$templateCache', '$http', | |
function ($templateCache, $http) { | |
// angular.js preload template factory, the purpose of this | |
// is to preload all of your applications templates, once. | |
// all callbacks should fire with (err, data) node.js style | |
// flow. | |
var internalHttpRequest = function (url, fn) { | |
$http.get(url).success(function (data) { | |
return fn(data); | |
}); | |
}; | |
var preload = function (templates, fn) { | |
var templates = templates || []; | |
if (templates.length) { | |
templates.forEach(function (template) { | |
internalHttpRequest(template, function (html) { | |
$templateCache.put(template, html); | |
}); | |
}); | |
return fn(null, true); | |
} else { | |
return fn(true, null); | |
} | |
}; | |
return preload; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do I get all URLs templates?
You use an array of URLs...
I'm doing this but I have too many.
$http.get('views/asistente/historial.html', { cache: $templateCache }).then(() => { }, error)
$http.get('views/asistente/historial.pedidointerno.html', { cache: $templateCache }).then(() => { }, error) $http.get('views/asistente/historial.recetas.html', { cache: $templateCache }).then(() => { }, error) $http.get('views/asistente/historial.transferencias.html', { cache: $templateCache }).then(() => { }, error)
...
..
.