Example of Service Inheritance

http://angularjs.org/

by boneskull

HTML

<script src="http://code.angularjs.org/1.1.5/angular.min.js"></script>
<div ng-controller="MyCtrl">{{state}}
    <br>{{seriesParam}}</div>

JavaScript

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

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

var baseService = function () {
    this._state = {};
};
baseService.prototype.getState = function () {
    return this._state;
};
baseService.prototype.setState = function (state) {
    this._state = state;
};

var chartService = function () {
    this._seriesParam = {};
};
chartService.prototype = Object.create(baseService.prototype);
chartService.prototype.getSeriesParam = function () {
    return this._seriesParam;
};
chartService.prototype.setSeriesParam = function (seriesParam) {
    this._seriesParam = seriesParam;
};

myApp.service('baseService', baseService);
myApp.service('chartService', chartService);

function MyCtrl($scope, chartService) {

    var state = {
        foo: 'bar'
    },
    seriesParam = {
        baz: 'spam'
    };

    chartService.setState(state);
    $scope.state = chartService.getState();

    chartService.setSeriesParam(seriesParam);
    $scope.seriesParam = chartService.getSeriesParam();
}