$http.get("http://localhost:8080/xampp/property-listing/db/listings.php",
{params: {"propFilter": "all"}})
.success( function (result) {
$scope.listings = result;
})
.error( function (data, status) {
console.log(data);
});
above code works perfectly in controller but as soon as i put it in custom
service it does not show anything infact shows undefined
My Service
----------------
app.service("propertyService", ["$resource", "$http", function ($resource,
$http) {
var self = this;
/*this.name = "Hamid Mir";
this.final_result;
this.nameLength = function() {
return self.name.length;
};
*/
this.getPropertyListings = function (pFilter) {
$http.get("http://localhost:8080/xampp/property-listing/db/listings.php",
{params: {"propFilter": pFilter}})
.success( function (result) {
self.final_result = result;
})
.error( function (data, status) {
self.final_result = data;
});
return self.final_result;
};
}]);
My Controller where I am suing it
----------------------------------------------------
app.controller("homeController", ["$scope", "propertyService", function
($scope, propertyService) {
$scope.listings = propertyService.getPropertyListings('all'); //does not
show anything and no error
console.log(propertyService.getPropertyListings('all')); // shows undefined
//console.log(propertyService.nameLength()); This works perfectly
}]);
any idea where I am doing wrong.
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.