Devo spostare la funzione getTemplates dal ritorno o cosa?AngularJS: Da una fabbrica, come posso chiamare un'altra funzione
Esempio: Non so che cosa per sostituire "XXXXXXX" con (ho provato "questo/auto/templateFactory", ecc ...):
.factory('templateFactory', [
'$http',
function($http) {
var templates = [];
return {
getTemplates : function() {
$http
.get('../api/index.php/path/templates.json')
.success (function (data) {
templates = data;
});
return templates;
},
delete : function (id) {
$http.delete('../api/index.php/path/templates/' + id + '.json')
.success(function() {
templates = XXXXXXX.getTemplates();
});
}
};
}
])
C'è un altro problema, 'templates = obj.getTemplates();' non funziona a causa dell'async. Puoi cambiare i getTemplates per restituire una promessa e poi ... lo sai :) – zsong