Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (47.6k points)

I recently posted a detailed description of the issue I am facing here at SO. As I couldn't send an actual $http request, I used a timeout to simulate asynchronous behaviour. Data binding from my model to view is working correctly.

Now, when I use $http instead of $timeout (tested locally), I could see the asynchronous request was successful and data is filled with json response in my service. But, my view is not updating.

1 Answer

0 votes
by (106k points)
edited by

For processing $http response in service you can return promise in your service and use then in your controller see the code below:-

Looking for Angularjs material from basics! Refer to this video on Angularjs provided by Intellipaat:

Code:

var app = angular.module('plunker', []); app.factory('myService', function($http) { 

return { 

async: function() {

 return $http.get('test.json'); 

//1. this returns promise 

}; 

}); 

app.controller('MainCtrl', function( myService,$scope) { 

myService.async().then(function(d) { 

//2. so you can use .then() 

$scope.data = d; 

}); 

});

Related questions

0 votes
1 answer
0 votes
1 answer
asked Aug 30, 2019 in Web Technology by Sammy (47.6k points)
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...