Angular: service()

http://angularjs.org/

by mrajcok

HTML

<div ng-controller="MyCtrl">
  {{txt}}
</div>

JavaScript

var myApp = angular.module('myApp',[]);

myApp.service('myService', function() {
    this.concatenate = function(text) {
        return text + "123";
    }
    this.somePrimitiveValue = 22;
});

function MyCtrl($scope, myService) {
    $scope.txt = myService.concatenate("abc");
    console.log(myService)
}