var myApp = angular.module('myApp', []); // Service myApp.service('helloWorldFromService', function () { this.sayHello = function () { return "Hello World from Service!" }; }); // Factory myApp.factory('helloWorldFromFactory', function () { return { sayHello: function () { return "Hello World from Factory!" } }; }); // Provider myApp.provider('helloWorld', function () { this.name = 'Default'; this.$get = function () { var name = this.name; return { sayHello: function () { return "Hello World " + name + "!" } } }; this.setName = function (name) { this.name = name; }; }); // Configuring a provider myApp.config(function (helloWorldProvider) { helloWorldProvider.setName('from Provider'); }); myApp.controller('myController', function ($scope, helloWorldFromService, helloWorldFromFactory, helloWorld) { $scope.hellos = [helloWorldFromService.sayHello(), helloWorldFromFactory.sayHello(), helloWorld.sayHello()]; });
<div ng-app="myApp" ng-controller="myController">{{hellos}}</div>