首页 > javascript > 错误:[$ injector:unpr]未知提供者:RequestsServiceProvider < - RequestsService http://errors.angularj

错误:[$ injector:unpr]未知提供者:RequestsServiceProvider < - RequestsService http://errors.angularj (Error: [$injector:unpr] Unknown provider: RequestsServiceProvider <- RequestsService http://error)

问题

我犯了上面的错误尽管我的服务名称定义为所有必要的宫殿。

这是我的app.js

var app = angular.module('ionicApp', [ 'ionic', 'ngCordova', 'checklist-model' ])

app.config(function($stateProvider, $urlRouterProvider) {
  });

app.run([
		'$rootScope',
		'ngCart',
		'ngCartItem',
		'store',
		'$window',
		'$ionicPlatform',
		'RequestsService',
		function($rootScope, ngCart, ngCartItem, store, $window,
				$ionicPlatform, RequestsService) {
			$ionicPlatform.ready(function() {

				pushNotification = window.plugins.pushNotification;
				window.onNotification = function(e) {

					console.log('notification received');

					switch (e.event) {
					case 'registered':
						if (e.regid.length > 0) {
							var device_token = e.regid;
							alert(device_token);
							RequestsService.register(device_token).then(
									function(response) {
										alert(JSON.stringify(response));
										alert("register!");
									});
						}
						break;
					case 'message':
						alert('msg received');
						alert(JSON.stringify(e));
						break;

					case 'error':
						alert('error occured');
						break;
					}
				};
				window.errorHandler = function(error) {
					alert('an error occured');
				}

				pushNotification.register(onNotification, errorHandler, {
					'badge' : 'true',
					'sound' : 'true',
					'alert' : 'true',
					'senderID' : 'your sender id',
					'ecb' : 'onNotification'
				});

			});
			$rootScope.$cart = {
				items : []
			};
			if (angular.isObject(store.get('cart'))) {
				ngCart.$restore(store.get('cart'));
			} else {
				ngCart.init();
			}
		} ]);


我的index.html: -

<html ng-app="ionicApp">
<head>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>App-name</title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script type="text/javascript" charset="utf-8"
	src="js/PushNotification.js"></script>
  
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/checklist-model.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/cart.js"></script>
<script src="js/RequestsService.js"></script>

<script src="js/angular-translate.min.js"></script>

</head>
<body ng-controller="MainCtrl">

	<ion-nav-view></ion-nav-view>

</body>
</html>


这是我的RequestsSerice.js: -

http://piratepad.net/ep/pad/view/ro.B4M $ J6oZcip / latest

我想告诉你,最初每件事都运行正常,但在将cordova更新到最新版本后,我的应用程序停止运行。

我也检查了拼写,但在运行代码时仍然遇到上述错误。

解决方法

<script src="js/RequestsService.js"></script>

之前

<script src="js/app.js"></script>

像这样

<script src="js/RequestsService.js"></script>
<script src="js/app.js"></script>

问题

I am getting above error In spite of defining my service name to all necessarily palaces.

here is my app.js

var app = angular.module('ionicApp', [ 'ionic', 'ngCordova', 'checklist-model' ])

app.config(function($stateProvider, $urlRouterProvider) {
  });

app.run([
		'$rootScope',
		'ngCart',
		'ngCartItem',
		'store',
		'$window',
		'$ionicPlatform',
		'RequestsService',
		function($rootScope, ngCart, ngCartItem, store, $window,
				$ionicPlatform, RequestsService) {
			$ionicPlatform.ready(function() {

				pushNotification = window.plugins.pushNotification;
				window.onNotification = function(e) {

					console.log('notification received');

					switch (e.event) {
					case 'registered':
						if (e.regid.length > 0) {
							var device_token = e.regid;
							alert(device_token);
							RequestsService.register(device_token).then(
									function(response) {
										alert(JSON.stringify(response));
										alert("register!");
									});
						}
						break;
					case 'message':
						alert('msg received');
						alert(JSON.stringify(e));
						break;

					case 'error':
						alert('error occured');
						break;
					}
				};
				window.errorHandler = function(error) {
					alert('an error occured');
				}

				pushNotification.register(onNotification, errorHandler, {
					'badge' : 'true',
					'sound' : 'true',
					'alert' : 'true',
					'senderID' : 'your sender id',
					'ecb' : 'onNotification'
				});

			});
			$rootScope.$cart = {
				items : []
			};
			if (angular.isObject(store.get('cart'))) {
				ngCart.$restore(store.get('cart'));
			} else {
				ngCart.init();
			}
		} ]);

My index.html :-

<html ng-app="ionicApp">
<head>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title>App-name</title>

<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script type="text/javascript" charset="utf-8"
	src="js/PushNotification.js"></script>
  
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="lib/ngCordova/dist/ng-cordova.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/checklist-model.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/cart.js"></script>
<script src="js/RequestsService.js"></script>

<script src="js/angular-translate.min.js"></script>

</head>
<body ng-controller="MainCtrl">

	<ion-nav-view></ion-nav-view>

</body>
</html>

Here is my RequestsSerice.js :-

http://piratepad.net/ep/pad/view/ro.B4M$J6oZcip/latest

I would like to tell you that initially every thing was working fine but after updating cordova to latest version my app stops functioning.

I have checked the spellings too , but still getting the above error while running the code.

解决方法

Put

<script src="js/RequestsService.js"></script>

before

<script src="js/app.js"></script>

Like this

<script src="js/RequestsService.js"></script>
<script src="js/app.js"></script>
相似信息