i have service which makes an $HTTP.GET request, at first i tried to access the object $$state but the value inside was undefined, so i went and red about promises and asynchronous calls here: http://blog.ninja-squad.com/2015/05/28/angularjs-promises/
after i red everything i tried again as guided but still it doesn't work for me :-(, please advise, i want to access the values object.
service:
function ConnectMe($http) {
function OnAction() {
this.create = function (search, key) {
return $http.get("https://www.tastekid.com/api/similar?q=" + search + "&verbose=1&k=" + key).then(function (response) {
return response.data;
});
};
}
var connection = new OnAction();
return function () {
return connection;
};
}
controller:
function TasteConroller($scope, ConnectMe) {
$scope.apiKey = "https://www.tastekid.com/api/similar?q=" + $scope.UserPick + "&verbose=1&k=254357-MatureAm-A31YEAIX";
$scope.UserPick = "red+hot+chili+peppers";
$scope.Key = "254357-MatureAm-A31YEAIX";
var srv = ConnectMe();
srv.create($scope.UserPick, $scope.Key).then(function(data) {
$scope.results = data;
}), function() {
$scope.error = 'unable to get the ponies';
};
console.log($scope.results);
function(data)passed to then()). So, put the console.log() inside that function.