<div ng-app="H2G2">
<div ng-controller="DeepThoughtController">
<a href ng-click="reset()">reset</a>
<a href ng-click="compute(6,9)">compute</a> {{response}}
</div>
</div>
<script>
angular.module('H2G2',['DeepThought']);
angular.module('DeepThought', []).factory('deepThought', function() {
var deepThought = {};
deepThought.compute = function(param) {...}
return deepThought;
});
var DeepThoughtController = function($scope, deepThought) {
$scope.reset = function () { $scope.response = "DeepThought~> ZzzZz...";}
$scope.reset();
$scope.compute = function(param1, param2) {
$scope.response = "La réponse est " + deepThought.compute(param1 * param2);
};
};
</script>