Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialTata Gelashvili
3,076 PointsAngular 1.x $http service problem.
When I try to receive data from api the app receives it but doesn't display.
app.controller('AppCtrl', function($scope, $http) {
$http.get('https://coinmarketcap-nexuist.rhcloud.com/api/eth')
.then(function(response) {
console.log(response);
$scope.title = response.data.price.usd;
});
});
I have tried it on W3schools and there it works normally but in my third project I have the same issue. http://www.w3schools.com/angular/tryit.asp?filename=try_ng_http_get I'm trying to make like this but unfortunately it doesn't works.
Tata Gelashvili
3,076 PointsHTML is 100% correct, the problem is here.
2 Answers
Matt Milburn
20,786 PointsGeorge, have you tried using $scope.$apply()
in your callback? This will help let Angular know to update the view once changes have been made to your model outside of Angular. If this doesn't solve your issue then I would suggest looking elsewhere in your code for the cause of the problem.
I revised your code with $scope.$apply
in use:
app.controller('AppCtrl', function($scope, $http) {
$http.get('https://coinmarketcap-nexuist.rhcloud.com/api/eth')
.then(function(response) {
console.log(response);
$scope.$apply(function() {
$scope.title = response.data.price.usd;
});
});
});
Ariel Kohan
15,519 PointsTry changing:
<span>{{ ethereum.price.usd}}</span>
To:
<span>{{ title}}</span>
Tata Gelashvili
3,076 PointsI've already tried it but it dosn't work
Ariel Kohan
15,519 PointsAriel Kohan
15,519 PointsCan you add the html? Maybe the problem is there.