var app =
angular.module('singletonApp',
[]);
app.controller('singletonTest', function ($scope, singletonService)
{
$scope.name = singletonService.getValue();
});
app.service('singletonService', function () {
var field = {
value: 'hello Anil'
};
var getValue = function () {
return val;
}
return {
getValue: getValue
};
});
HTML code
<div ng-app="singletonApp">
<input type="text" ng-model="name.value" />
</div>
</div>
For more, go to link
http://blog.jdriven.com/2013/03/how-to-create-singleton-angularjs-services-in-4-different-ways/
http://blog.jdriven.com/2013/03/how-to-create-singleton-angularjs-services-in-4-different-ways/