我的Angular代碼在它自己的工作上很好,但是一旦我將它放入RoR項目中,然後我收到您在標題中列出的錯誤 -RoR - 角度錯誤:未知的提供者:mWebSrvcProvider < - mWebSrvc
//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的項目文件結構如下:
我甚至試過命名scripts目錄「腳本」,以確保它加載後mWeb.js,以及控制器以確保mWebCtrl.js在mWebSrvc.js之後加載,但無濟於事。
我已經使用無數的Angular項目的目錄結構,它可以GET或POST到JSON文件,沒有問題。
爲什麼這個相同的代碼在獨立的Angular而不是RoR中工作?
我相信我知道爲什麼,我不能相信這之前,我不明白,我,但我不得不在coffeescript中重寫所有這一切 – kronus