<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-controller="PruebaController">
idioma = {{idioma}}
<br>
suma de 3 + 6 = {{suma}}
<br>
area = {{area}}
</body>
</html>
var app=angular.module("app",[]);
app.constant("idioma","es-es");
app.constant("matematicas_simples",{
sumar:function(a,b) {
return a+b;
},
restar:function(a,b) {
return a-b;
}
});
app.constant("radio",10);
app.constant("area",function(radio) {
return 3.1416*radio*radio;
})
app.controller("PruebaController",["$scope","idioma","matematicas_simples","radio","area",function($scope,idioma,matematicas_simples,radio,area) {
$scope.idioma=idioma;
$scope.suma=matematicas_simples.sumar(3,6);
$scope.area=area(radio);
}]);
ejemplo de constant