Created
February 27, 2015 15:50
-
-
Save washingtonsoares/b0498ad14c1dd49275fe to your computer and use it in GitHub Desktop.
This file contains 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
angular.module('starter.services', []) | |
.factory('Chats', function($http) { | |
// Might use a resource here that returns a JSON array | |
chats = []; | |
$http.get('http://localhost:3000/api/chats.json') | |
.success( | |
function (data) { | |
console.log(data); //aqui ele consegue exibir os dados | |
chats = data; | |
console.log(chats); //aqui eu passo os valores de "data" para a variavel "chats" | |
}) | |
.error( | |
function (data) { | |
console.log('server side error occurred. !!!!!!! '); | |
}); | |
console.log(chats); //aqui ele exibe um Array vazio | |
return { | |
all: function() { | |
return chats; | |
}, | |
remove: function(chat) { | |
chats.splice(chats.indexOf(chat), 1); | |
}, | |
get: function(chatId) { | |
for (var i = 0; i < chats.length; i++) { | |
if (chats[i].id === parseInt(chatId)) { | |
return chats[i]; | |
} | |
} | |
return null; | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment