我已将 requirejs 与我的 Angular 应用程序集成。但是在加载应用程序时,它给了我一个错误'Argument 'appCtrl' is not a function, got undefined'
这是我的控制器代码:
define(['Angular'], function (angular) {
function appCtrl($scope, pathServices) {
alert('sa');
}
function homeCtrl($scope, brandService) {
console.log('dfd');
}
});
随之而来的是,它给出了错误'unknown provider pathServices'
服务代码是:
服务配置.js
define([
'Angular',
'common/Services/services',
'current/js/services'
], function(angular, commonServices, loacalStorageServices, currentServices) {
"use strict";
var services = {
commonServices : commonServices,
currentServices : currentServices,
};
var initialize = function (angModule) {
angular.forEach(services,function(service, name) {
angModule.service(name, service);
});
}
return {
initialize: initialize
};
});
常见/services.js
define(['Angular'], function (angular) {
var app = angular.module('myApp.services', []);
app.factory('pathServices', function($http, $q, $rootScope) {
function pathServices() {
alert('as');
}
return new pathServices();
});
app.factory('anotherServices', function($http, $q, $rootScope) {
function anotherServices() {
alert('as');
}
return new anotherServices();
});
});
当前/services.js
define(['Angular'], function(angular) {
var app = angular.module('myApp.services', []);
app.factory('brandsService', function() {
function brandsService() {
var autoCompleteData = [];
this.getSource = function() {
return autoCompleteData;
}
this.setSource = function(states) {
autoCompleteData = states;
}
}
return new brandsService();
});
});
在 serviceConfig.js 中,我包含了 2 个服务文件。但问题是,最后一个 current/service.js 文件覆盖了所有文件。如何包含多个服务文件?
我是requirejs的新手。如何使用 requirejs 使用控制器功能和服务?任何人都可以帮忙吗?