Q. AngularJS Services
In AngularJS you can make your own service, or use one of the many built-in services.
- built-in services always start with $ (e.g.
$http
).
In AngularJS, a service is a function, or object, that is available for, and limited to, your AngularJS application.
Q. Create Your Own Service
var app = angular.module('myApp', []);
app.service('hexafy', function() {
this.myFunc = function (x) {
return x.toString(16);
}
});
Q. Use Your Own Service
app.controller('myCtrl', function($scope, hexafy) {
$scope.hex = hexafy.myFunc(255);
});