Reputation: 19700
I have the following javascript:
var myApp = angular.module('myApp', []);
myApp.factory( "TestService", function() {
return {
clickString: "click me",
clickStringProxy: this.clickString
}
});
function MyCtrl($scope, TestService) {
$scope.clickString = TestService.clickString;
$scope.clickStringProxy = TestService.clickStringProxy;
}
The above is my failed attempt in trying to make TestService.clickStringProxy
access TestService.clickString
(through an elementary 'this').
JsFiddle: http://jsfiddle.net/eDb2S/96/
How would I go about allowing functions within a service to access each other?
I've tried various atempts to remedy the situation but to no avail.
Upvotes: 0
Views: 145
Reputation: 19748
Declare the service object manipulate it and return.
myApp.factory( "TestService", function() {
var service= {
clickString: "click me"
}
service.clickStringProxy = service.clickString;
return service;
});
Upvotes: 1