I created a service that has a method that does a simple calculation. It takes a value and squares it. However, I'm getting an error saying that square is undefined so I'm guessing I'm passing in the value incorrectly.
jsfid: http://jsfiddle.net/ADukg/19107/
var myApp = angular.module('myApp',[]);
//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});
/* function MyCtrl($scope) {
$scope.name = 'Superhero';
} */
myApp.controller('MyCtrl', ['$scope', function($scope, CalcService) {
var cheese = CalcService.square(2);
$scope.value = cheese;
}]);
myApp.service('CalcService', function(x){
this.square = function(x) {
var y = x*x;
return y;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-controller="MyCtrl">
Hello, {{value}}!
</div>
xto the service function. You should remove it. Check this updated jsFiddle: jsfiddle.net/ADukg/19114myApp.controller('MyCtrl', function($scope, CalcService) {}but this won't work when you minify your file.