Created
June 4, 2015 13:11
-
-
Save pavlo-yuriychuk/bd187272c10a9c9c6deb to your computer and use it in GitHub Desktop.
Angular service
This file contains 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
'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