TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Own Service in AngularJS
Ajay Malik
Aug 19
2016
Code
855
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
<!DOCTYPE html
>
<
html
>
<
script
src
=
"http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"
>
</
script
>
<
body
>
<
div
ng-app
=
"myApp"
ng-controller
=
"myCtrl"
>
<
p
>
The hexadecimal value of 2555 is:
</
p
>
<
h1
>
{{hex}}
</
h1
>
</
div
>
<
p
>
A custom service whith a method that converts a given number into a hexadecimal number.
</
p
>
<
script
>
var
app
=
angular
.module('myApp', []);
app.service('hexafy', function() {
this.myFunc
=
function
(x) {
return x.toString(16);
}
});
app.controller('myCtrl', function($scope, hexafy) {
$
scope.hex
=
hexafy
.myFunc(2555);
});
</
script
>
</
body
>
</
html
>
service
AngularJS