Last active
December 18, 2015 14:09
-
-
Save amitaibu/5794822 to your computer and use it in GitHub Desktop.
Angular http service.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module("appName") | |
.factory("productService", function() { | |
var cache = $cacheFactory("productService"); | |
return { | |
gettingProducts: function(id){ | |
var defer = $q.defer(); | |
var product = store.get(id); | |
if (!product){ | |
var httpPromise = $http.get("/products.json"); | |
httpPromise.then( | |
function success(result){ | |
} , | |
function error(error){} | |
) | |
return httpPromise; | |
} | |
defer.resolve(product); | |
return defer.promise; | |
} | |
/* var products = gettingProducts(1); | |
gettingProducts(1).then(function success(products){ | |
$scope.product = gettingProduct(1); | |
}) | |
$scope.$watch("product", function(product, oldValue){ | |
$scope.variants = product | |
}) | |
$scope.variants = $scope.products[0] | |
*/ | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment