iterate service functions

by przno

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js"></script>
<div ng-app="myApp">
    <div ng-controller="myController"></div>
</div>

JavaScript

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

    myApp.service('myService', function () {
        return {
            hello: function () {
                return "hello";
            },
            world: function () {
                return "world";
            }
        };
    });

    myApp.controller('myController', function (myService) {
        var total = 0;

        for (var i in myService) {
            if (myService.hasOwnProperty(i)) {
                console.log('myService has: ', i);
                total++;
            }
        }

        console.log('total ', total);

    });

})();