我正在运行此代码,这是平方的数字,它在控制台上生成一些我无法获取的错误。
错误
我的代码在这里
<html>
<head>
<title>Angular JS Services</title>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="mainApp" ng-controller="CalcController">
<p>Enter a number: <input type="number" ng-model="number" />
<button ng-click="square()">X<sup>2</sup></button>
<p>Result: {{result}}</p>
</div>
<script>
var mainapp = angular.module("mainApp", []);
mainapp.factory('MathObjasService', function(a){
var factorysrrvice = {};
factorysrrvice.multiply = function(a, b){
return a * b;
}
return factorysrrvice;
});
mainapp.service("CalSquareService", ["MathObjasService", function(MathObjasService){
this.doubling = function(a){
return MathObjasService.multiply(a, a);
}
}]);
mainapp.controller("CalcController", ["$scope", "CalSquareService", function($scope, CalSquareService){
$scope.square = function(){
$scope.result = CalSquareService.doubling($scope.number);
}
}]);
</script>
</body>
</html>
有人可以帮我解决我出问题的地方吗?
最佳答案
您在工厂中没有注入名为a
的服务
mainapp.factory('MathObjasService', function(a){
^^^ -> unknown provider
只需从工厂删除
a
这样尝试
mainapp.factory('MathObjasService', function(){});
关于javascript - Angular Js引用误差,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32324290/