Skip to content

Instantly share code, notes, and snippets.

@AFelipeTrujillo
Created February 26, 2016 18:45
Show Gist options
  • Save AFelipeTrujillo/83032297a67347f502b0 to your computer and use it in GitHub Desktop.
Save AFelipeTrujillo/83032297a67347f502b0 to your computer and use it in GitHub Desktop.
<div ng-app="app" ng-controller="controller">
<p>
Default Value: {{value}}
</p>
<p>
is {{number}} Even Number? {{result}}
</p>
<p>
{{sum}} {{pi}}
</p>
</div>
var app = angular.module('app',[]);
app.constant('PI',3.1416);
app.config(function($provide){
$provide.provider('otherService',function(PI){
this.$get = function(){
var factory = {};
factory.add = function(a,b){
return a + b;
}
factory.PI = PI;
return factory;
}
})
});
app.value('defaultValue',100);
app.factory('mathFactory',function(){
var factory = {};
factory.mod = function(a,b){
return a % b;
}
return factory;
});
app.service('calcService',function(mathFactory){
this.isEven = function(a){
return mathFactory.mod(a,2) === 0;
}
});
app.controller('controller',function($scope,defaultValue,calcService,otherService){
$scope.value = defaultValue;
$scope.number = 14;
$scope.result = calcService.isEven($scope.number);
$scope.sum = otherService.add(1,2);
$scope.pi = otherService.PI
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment