AngularJS service types, at their core, are singleton containers used for unified resource access across your application. Sometimes, the resource access will just be a single JS object. For this, AngularJS offers service values and service constants.
Service values and service constants both act in a very similar way, but with one important difference.
The service value is the simplest of all service types. The value
service acts as a key-value pair and can be injected and used as follows:
(app.js) angular.module('myApp', []) .controller('Ctrl', function($scope, MyValue) { $scope.data = MyValue; $scope.update = function() { MyValue.name = 'Brandon Marshall'; }; }) .value('MyValue', { name: 'Tim Tebow', number: 15 });
An example of template use is as follows:
(index.html) <div ng-app="myApp"> <div ng-controller="Ctrl"> <button ng-click="update()">Update</button> {{ data.name }} #{{...