저는 AngularJs에서 새로 왔습니다. AngularJS에서 컨트롤러에 서비스를 주입하는 데 문제가 있습니다. 내가 유래에 많은 자습서 및 주제를 읽을 수 있지만 컨트롤러 & 서비스가이 같은 동일한 모듈을 사용하기 때문에 내 문제를 해결할 수 없습니다AngularJs, 컨트롤러에 서비스를 삽입하십시오.
서비스 & 컨트롤러가 동일한 모듈을 사용하면 내 프로젝트가 작동var myModule = angular.module("myModule", []);
myModule.service("myService", MyService);
myModule.controller("MyController", function($scope, myService) {
myService.doIt();
});
, 많은 컨트롤러가이 서비스를 사용해야하기 때문에 각 모듈이 자체 모듈을 사용하기를 원합니다.
<!doctype html>
<html lang="en" ng-app="interfaceApp">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<head>
<meta charset="utf-8">
<title>Interface de consulation</title>
<link rel="stylesheet" href="resources/css/bootstrap.css">
<link rel="stylesheet" href="resources/css/app.css">
<link rel="stylesheet" href="resources/css/animations.css">
<script src="resources/vendors/jquery/jquery.js"></script>
<script src="resources/vendors/angular/angular.min.js"></script>
<script src="resources/vendors/angular/angular-animate.js"></script>
<script src="resources/vendors/angular/angular-route.js"></script>
<script src="resources/vendors/angular/angular-resource.js"></script>
<!--personal script-->
<script src="js/controllers/router.js"></script>
<script src="js/animations/animations.js"></script>
<script src="js/filters/filters.js"></script>
<script src="js/services/services.js"></script>
<script src="js/services/deserializer.js"></script>
<script src="js/directives/directives.js"></script>
<!-- load my controller -->
<script src="js/controllers/phoneController.js"></script>
<script src="js/controllers/specimenController.js"></script>
<script src="js/controllers/localisationController.js"></script>
</head>
<body>
<!-- MAIN CONTENT AND INJECTED VIEWS -->
<div class="view-container">
<div ng-view class="view-frame"></div>
</div>
</body>
</html>
router.js :
'use strict';
/* App Module */
var interfaceApp = angular.module('interfaceApp', [
'ngRoute',
'phoneModules',
'localisationModules',
'specimenModules',
'interfaceFilters',
'interfaceDirectives',
'interfaceAnimations',
'interfaceServices',
// 'DeserializerService' // Error: [$injector:modulerr]
]);
interfaceApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/', {
templateUrl: 'partials/home.html',
controller: 'MainCtrl'
}).
when('/specimens', {
templateUrl: 'partials/specimen/list.html',
controller: 'specimenListeCtrl'
}).
when('/specimens/:specimensId', {
templateUrl: 'partials/specimen/detail.html',
controller: 'specimenDetailCtrl'
}).
otherwise({
redirectTo: '/'
});
}]);
JS의/C를
는
index.html을 (내가 코드를 최소화하려고) ontrollers/specimenController.js :
'use strict';
/* Controllers */
var specimenModules = angular.module('specimenModules', ['ngRoute']);
...
var referencedTag={"mediasSet":"@mediasSet","determinations":"@determinationID"};
specimenModules.controller('specimenListeCtrl', ['$scope', '$http', 'DeserializerService',
function ($scope,$http,DeserializerService) {
var request = 'http://localhost:8888/ui/specimens?limit=10&r_medias=false&orderby=d_determinationid';
$http.get(request).success(function(data) {
DeserializerService.startDeserializer(data,referencedTag);
$scope.specimens=data;
});
}
]);
JS/서비스/deserializer.js :
var deserializerModule = angular.module('DeserializerModule', []);
deserializerModule.service('DeserializerService', function() {
***//specimenModules.service('deserializerService', function() { // work but i dont want to use specimenModules her***
this.referencedTag= [];
this.startDeserializer= function(data,refTag) {
this.referencedTag=refTag;
this.deserializer(data);
}
this.deserializer= function(data) {
...
}
});
나는 많은 조합을 시도했지만 모두 같은 오류를주고 실패 : 오류 : [$ 인젝터 : modulerr] 오류 : [$ injector : unpr] 하지만 파이어 버그의 출처가 보이지 않습니다. (오류는 줄이나 파일을주지 마십시오) 오류 :
Error: [$injector:unpr] http://errors.angularjs.org/1.2.17/$injector/unpr?p0=DeserializerServiceProvider%20%3C-%20DeserializerService
u/<@http://localhost/rec-interface/resources/vendors/angular/angular.min.js:6:443
ec/l.$injector<@http://localhost/rec-interface/resources/vendors/angular/angular.min.js:36:139
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:34:195
ec/p.$injector<@http://localhost/rec-interface/resources/vendors/angular/angular.min.js:36:209
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:34:195
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:34:409
f/<[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:35:101
Od/this.$get</<@http://localhost/rec-interface/resources/vendors/angular/angular.min.js:66:463
ngViewFillContentFactory/<[email protected]://localhost/rec-interface/resources/vendors/angular/angular-route.js:913:1
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:54:85
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:47:55
v/<@http://localhost/rec-interface/resources/vendors/angular/angular.min.js:46:253
O/<@http://localhost/rec-interface/resources/vendors/angular/angular.min.js:47:485
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:51:245
[email protected]://localhost/rec-interface/resources/vendors/angular/angular-route.js:871:1
Yd/this.$get</[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:113:355
updateRoute/<@http://localhost/rec-interface/resources/vendors/angular/angular-route.js:552:15
ze/e/l.promise.then/[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:99:243
ze/e/l.promise.then/[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:99:243
ze/f/<.then/<@http://localhost/rec-interface/resources/vendors/angular/angular.min.js:100:407
Yd/this.$get</[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:111:110
Yd/this.$get</[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:108:180
Yd/this.$get</[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:111:449
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:72:113
[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:76:463
ve/</[email protected]://localhost/rec-interface/resources/vendors/angular/angular.min.js:78:1
<div ng-view="" class="view-frame ng-scope">
도움을 주셔서 감사합니다. 어떤 조언이나 비평가도 환영합니다.
난 당신'에서'DeserializerModule'을 포함 할 필요가 있다고 생각
덕분에 ...
: 는 모듈 하나 하나의 서비스 이름을 두 번 "주입"필요 표본 모듈 '을 사용하기 때문입니다. 도움을 청하는 – jcubic
thx. 누가 그것을 포함시킬 것인가? 나는 이것을 포함한다고 생각한다 :specimenModules.controller ('specimenListeCtrl', ''$ http ','DeserializerService ', – AlainIb
내가 생각하는 :'var specimModules = angular.module ('specimenModules ',' 'ngRoute ','DeserializerModule ']);' – jcubic