I\'m trying to use $http, but why it return null result?
angular.module(\'myApp\')
.factory(\'sender\', function($http) {
var newData = null;
$http.get(\
This JavaScript code is asynchronous.
console.log(newData)
return newData
Is executed before what inside success
newData = data;
console.log(newData)
So at first time, the newData is null (you set it to be null)
And when the http response is returned (inside the success), the newData gets its new value.
This is very common in Javascript, you should do all your work inside the success.