在angular js中添加自定义服务时出现错误,它显示了一些依赖注入问题。无法弄清楚如何解决
无法获取解决方案,请帮忙
我已经创建了app.js文件
var myModule = angular.module("myModule",["ngRoute"]);
myModule.config(['$routeProvider',function($routeProvider) {
$routeProvider
.when("/", {
template : "welcome"
})
.when("/add", {
templateUrl : "/add/add.html",
controller : "myController2"
});
}]);
我的服务文件名为myservice.js
myModule.factory('exportService', function(){
return{
downloadData = function(){
console.log("in download data methodd");
$http.get("https://www.w3schools.com/angular/customers.php")
.then(function(response){
$scope.data = response.data;
}, function(error){
console.log("error occured");
});
}
}
});
我的控制器文件
myModule.controller('myController2',function($scope,exportService){
exportService.downloadData();
});
我的index.html文件
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<script src="./app.js"></script>
<script src="./add/add.html"></script>
<script src="./add/add.js"></script>
<script src="./add/myservice.js"></script>
</head>
<body ng-app="myModule">
<div ng-controller="myController2">
<div>
<input type="text" ng-model="message"/>
{{message}}
</div>
</div>
<div ng-view></div>
</body>
</html>
我遇到错误,因为错误:$ injector:unpr 未知提供者 未知的提供程序:exportServiceProvider <-exportService <-myController2