Javascript AngularJS模块设置

Javascript AngularJS模块设置,javascript,angularjs,Javascript,Angularjs,直到最近,我一直在把我所有的函数都放到一个大的JS文件中。我现在正试图将这些模块分解成小模块,以使我的应用程序更易于移植 我的核心js文件(main.js)包含以下代码: var App = angular.module("app", ['ui.bootstrap', 'angularMoment', 'chieffancypants.loadingBar', 'ngAnimate', 'ui.sortable', 'ngSanitize'], function ($interpolatePr

直到最近,我一直在把我所有的函数都放到一个大的JS文件中。我现在正试图将这些模块分解成小模块,以使我的应用程序更易于移植

我的核心js文件(main.js)包含以下代码:

var App = angular.module("app", ['ui.bootstrap',  'angularMoment', 'chieffancypants.loadingBar', 'ngAnimate', 'ui.sortable', 'ngSanitize'], function ($interpolateProvider, $httpProvider) {
        $interpolateProvider.startSymbol('[[');
        $interpolateProvider.endSymbol(']]');
        $httpProvider.defaults.transformRequest = function (data) {
            if (data === undefined) {
                return data;
            }
            return $.param(data);
        };
        $httpProvider.defaults.headers.post['Content-Type'] = ''
        + 'application/x-www-form-urlencoded; charset=UTF-8';
        $httpProvider.defaults.headers.post['X-Requested-With'] = ''
        + 'XMLHttpRequest';
    });
在另一个文件(即blog.module.js)中,我有以下内容:

        (function(window, angular, undefined) {

        'use strict';

        angular.module("app", [])
        .controller('Blog', ['$scope', function ($scope) {
            alert('test');
        }]);
    });
虽然main.js文件及其所有依赖项都会加载,但第二个文件不会加载。控制器基本上找不到。谁能给我指点一下我可能会出什么差错


谢谢

blog.module.js中的sintax看起来像是您正在尝试创建两个同名“app”的模块。 像这样更改控制器模块

(function(window, angular, undefined) {

'use strict';

angular.module("app")
.controller('Blog', ['$scope', function ($scope) {
    alert('test');
}]);
});
我引述你的话:

App = angular.module("app", ['ui.bootstrap', 
...
 angular.module("app", [])
你不能重新声明一个模块,你可以重新打开它

App = angular.module("app", ['ui.bootstrap', 
...
 angular.module("app")
或者创建另一个

App = angular.module("app", ['ui.bootstrap', 'app.controller'
...
angular.module("app.controller")

我最终使用:[代码]“严格使用”;controller('Blog',function($scope,$log){$scope.hello=“Test”;$log.log($scope.hello);});[/code]有效。找不到格式化此内容的方法。