<!doctype html>
<html ng-app="myModule">
<head>
<script src="../lib/js/angular.min.js"></script>
</head>
<body>
<script>
var myModule = angular.module('myModule', []);
myModule.factory('greeter', function($window){
return {
greet: function(text){
$window.alert(text);
}
};
});

function myController($scope,greeter,notify){
$scope.sayHello = function(){
greeter.greet('Hello, world!');
}
$scope.callNotify = function(msg){
notify.say(msg);
};
// scope.callNotify = function(msg){
// notify(msg);
// };
}

// myModule.factory('notify', function($window){
// var msgs = [];
// return function(msg){
// msgs.push(msg);
// if(msgs.length==3){
// console.info(msgs);
// $window.alert(msgs.join("\n"));
// msgs = [];
// }
// }
// });
myModule.service('notify', function($window){
var msgs = [];
return this.say = function(msg){
msgs.push(msg);
if(msgs.length==3){
console.info(msgs);
$window.alert(msgs.join("\n"));
msgs = [];
}
}
});
</script>
<div ng-controller="myController">
<button ng-click="sayHello()">Hello</button>
<input type="text" ng-model="message" />
<button ng-click ="callNotify({{'message'}})">Notify</button>
</div>
</body>
</html>