Skip to content

Instantly share code, notes, and snippets.

@pavlo-yuriychuk
Created June 4, 2015 13:11
Show Gist options
  • Save pavlo-yuriychuk/bd187272c10a9c9c6deb to your computer and use it in GitHub Desktop.
Save pavlo-yuriychuk/bd187272c10a9c9c6deb to your computer and use it in GitHub Desktop.
Angular service
'use strict';
angular.constant('Environment', {
ROOT_URL: 'https://api.harmonic.com/v1'
});
angular.factory('Services', ['Environment', 'lodash', '$resource', function (Environment, lodash, $resource) {
return $resource(Environment.ROOT_URL, {
get: {
method: 'GET',
isArray: true
},
getById: {
method: 'GET'
},
update: {
method: 'PUT'
},
delete: {
method: 'DELETE'
},
create: {
method: 'POST'
}
});
}]);
angular.controller('ServicesCtrl', ['$scope', 'Services', function ($scope, Services) {
$scope.filters = {};
$scope.init = function () {
Services.get().then(function (data) {
var items = _.findWhere(data, $scope.filters);
$scope.items = items;
}, function (err) {
})
}
}])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment