AngularJS Live Example

HTML

<div ng:app="MyServiceModule">
 <div ng:controller="myController" ng:init="initdata()">
 <p>Let's try this simple notify service, injected into the controller...</p>
 <input ng:init="message='test'" type="text" ng:model="message" />
 <button ng:click="callNotify(message);">NOTIFY</button>
 </div>
</div>

CSS

</style>
<script src="http://ci.angularjs.org/job/angular.js-angular-master/ws/build/angular.min.js"></script>
<style>
.ng-invalid { border: 1px solid red; } 
body { font-family: Arial,Helvetica,sans-serif; }
body, td, th { font-size: 14px; margin: 0; }
table { border-collapse: separate; border-spacing: 2px; display: table; margin-bottom: 0; margin-top: 0; -moz-box-sizing: border-box; text-indent: 0; }
a:link, a:visited, a:hover { color: #5D6DB6; text-decoration: none; }
.error { color: red; }

JavaScript

angular.
 module('MyServiceModule', []).
 factory('notify', ['$window', function(win) {
    var msgs = [];
    return function(msg) {
      msgs.push(msg);
      if (msgs.length == 3) {
        win.alert(msgs.join("\n"));
        msgs = [];
      }
    };
  }]);

function myController($scope, notify) {
  $scope.callNotify = function(msg) {
    notify(msg);
  };
  $scope.initdata = function() {
  alert('test2');
  };
$scope.$on('$viewContentLoaded', function(event) {
alert('test');
});
}

myController.$inject = ['notify'];