It seems like you want to access a service in the view, so the simplest way is to assign the service to a $scope variable:
$scope.service = $service;
This way, every method from the service can be directly called from the view without needing to create any special $scope methods.
If only one specific method needs to be called with different parameters, you could do:
$scope.call = function(){ ExampleSvc.call.call(this,'param', 'FirstCtrl'); };
In this case, an anonymous function is created to call the call method with the desired parameters.
However, if the service varies with each usage, a better approach would be to return it in the service constructor. This allows for creating a new object of the service each time by using the new keyword.
//service code
return function(controller){
this.controller=controller;
//methods here ...
};
//controller code
$scope.service = new service("ControllerName");
With this approach, different service objects can be used for each instance, avoiding the singleton pattern typical of services. An example implementing this approach is shown below:
var app = angular.module("app",[]);
app.controller("cont1",function($scope,person){
$scope.p = new person("Tom","Hanks");
});
app.controller("cont2",function($scope,person){
$scope.p = new person("Will","Smith");
});
//our service which returns constructor
app.service("person",function(){
return function(name,surname){
this.name = name;
this.surname = surname;
this.getName = function(){
return this.name;
};
this.getSurname = function(){
return this.surname;
};
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app">
<div ng-controller="cont1">
<span> Person is: <b>{{ p.getName() }} {{ p.getSurname() }}</b></span>
</div>
<div ng-controller="cont2">
<span> Person is: <b>{{ p.getName() }} {{ p.getSurname() }}</b></span>
</div>
</div>
This approach allows for using the service in a flexible manner by creating new objects. Assigning it to scope enables running the configured object directly there.