Skip to content

Instantly share code, notes, and snippets.

@AFelipeTrujillo
Created February 24, 2016 01:30
Show Gist options
  • Save AFelipeTrujillo/fb06b0049534291f58b3 to your computer and use it in GitHub Desktop.
Save AFelipeTrujillo/fb06b0049534291f58b3 to your computer and use it in GitHub Desktop.
<div ng-app="app" ng-controller="controller">
<div>
<input type="number" ng-model="number" />
<button ng-click="square()">
Square
</button>
</div>
<div>
Result: {{result}}
</div>
</div>
var app = angular.module('app',[]);
app.factory('MathFactory',function(){
var factory = {};
factory.add = function(a,b){
return a + b;
}
factory.subtraction = function(a,b){
return a - b;
}
factory.multiply = function(a,b){
return a * b;
}
return factory;
})
app.service('Calc',function(MathFactory){
this.square = function(a){
return MathFactory.multiply(a,a);
}
});
app.controller('controller',function($scope,Calc){
$scope.result = 2;
$scope.square = function(){
$scope.result = Calc.square($scope.result)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment