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 trialryan champin
16,836 PointsAngular.js Factories using $http
Im currently messing around learning Angular. I have a controller thats hooked up to a radial progress bubble, i am creating a factory that uses $http to grab some dummy data from data.json I inject the factory into my controller and set that data into a variable so i can use it inside some other objects. To be exact, i want to take the first element of the returned array from my json file as the dashOffset property on the circle object. When i console.log() Data.getData() in my controller it prints out some weird object...i think it's a promise object...i need this to be an array
var app = angular.module('app',['ui.router'])
.factory('Data', function($http){
return {
getData : function(){
var test = $http.get('data.json').success(function(res){
return res;
});
return test;
}
}
})
.controller('radial', function($scope, Data){
console.log(Data.getData().keys())
$scope.circle = {
size : 110,
stroke : '#2C3E50',
strokeWidth : 10,
radius : 48,
dashArray : Math.PI * 2 * 48,
dashOffset : (Math.PI * 2 * 48)
}
$scope.circleBG = {
size : 110,
stroke : '#2C3E50',
strokeWidth : 10,
radius : 48,
dashArray : Math.PI * 2 * 48,
dashOffset : (Math.PI * 2 * 48)
}
});