내 앵귤러 코드는 자체적으로 정상적으로 작동하지만 일단 RoR 프로젝트 내부에 배치하면 제목에 표시된 오류 메시지가 나타납니다 -RoR - 각도 오류 : 알 수없는 공급자 : mWebSrvcProvider <- mWebSrvc
app> assets> javascript> mAngular> mWeb.js
app> assets> javascript> mAngular> scripts> services> mWebSrvc.js
app> assets> javascript> mAngular> scripts> controllers> mWebCtrl.js
나는 심지어 후 mWeb.js뿐만 아니라 컨트롤러를로드하도록 보장하기 위해 스크립트 디렉토리 "스크립트"이름을 시도한 다음과 같이
//all the common/models are added to this.. so we can re-use across apps
var mainApp = angular.module('mainApp', ['ngResource', 'ngSanitize', 'ngCookies', 'ui.bootstrap']);
//app for all flows
var mWebApp = angular.module('mWebApp', ['mainApp', 'mWebApp.mWebSrvc', 'mWebApp.mWebCtrl'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'angular/views/index.html',
controller: 'mWebCtrl'
})
.otherwise({
redirectTo: '/'
});
}]);
var mGlobolJson = [];
var mWebCtrl = function($rootScope, $scope, $timeout, $location, mWebSrvc) {
$scope.nav_tpl = 'angular/views/nav.html';
$scope.footer_tpl = 'angular/views/footer.html';
$scope.Index = null;
$scope.loc = "";
$scope.loc = $location.path();
$scope.go = function(hash){
$scope.loc = $location.path();
$location.path(hash);
}
mWebSrvc.getCustomers(function(data){
$scope.items = data;
mGlobolJson = data;
});
$scope.doNothing = function(){}
$scope.myEnlargeImage = function(someParamComing){
var newWin = window.open("", name="_blank", "width=1270,height=952,toolbar=0,status=1,menubar=0,top=0,left=0,location=0,outerWidth=1270,outerHeight=952");
var htmlVar = "";
htmlVar += "<html><body bgcolor='#666'><img id='myLargerImage' style='position: absolute; top: -5px; left: -5px;' src="+someParamComing+" /></body></html>";
newWin.document.write(htmlVar);
}
}
mainApp.controller('mWebCtrl', mWebCtrl);
var mWebSrvc = function($http, $log) {
this.getCustomers = function() {
$http({
method : 'POST',
url : 'http://localhost:3000/api/customers/'
}).success(function(data, status, headers, config) {
$log.log('Done');
angular.forEach(data, function(c) {
$log.log(c.Title);
});
customers = data;
return customers;
});
};
this.insertCustomer = function(Title, h1, Comments, Comments2, download_coupon) {
var topID = customers.length + 1;
customers.push({
id : topID,
Title : Title,
h1 : h1,
Comments : Comments,
Comments2 : Comments2,
download_coupon : download_coupon
});
};
this.getCustomer = function(id) {
};
this.deleteCustomer = function(id) {
};
}
mainApp.service('mWebSrvc', mWebSrvc);
의 RoR 프로젝트의 파일 구조는 mWebCtrl.js가 mWebSrvc.js 뒤에로드되지만 아무 소용이 없도록 보장해야합니다.
저는 GET 또는 JSON 파일에 POST 할 수있는 수많은 프로젝트에 문제없이 디렉토리 구조를 사용했습니다.
왜이 동일한 코드가 RoR의 독립형 및 독립형에서 작동합니까?
의 RoR와 함께 완벽하게 작동 내 이 모든 것을 coffeescript로 다시 작성하십시오. – kronus