Using angularJS with requireJS - cannot read property 'module' of undefined

后端 未结 2 1259
臣服心动
臣服心动 2021-02-10 22:46

I had started writing an app using angularJS. After a few weeks, I suddenly realized that I should have used require JS from the beginning to load my modules. Yes, I know, it wa

2条回答
  •  难免孤独
    2021-02-10 23:22

    There are 2 possible problems with your setup:
    1. You are bootstrapping angular in your main.js and then loading the dependencies.
    2. You should be referencing the dependency using string

    So, after removing the angular.bootstrap from your main.js, try the following:

    app.js

    define([
        'AngularApp/services',
        'AngularApp/directives',
        'AngularApp/controllers'],
        function()
        {
            console.log("sup");
            var serviceContractModule = angular.module('ServiceContractModule',[ 'ngRoute', 'ServiceContractModule.services', 'ServiceContractModule.directives', '<>' ]);
            serviceContractModule.config(function($routeProvider,$locationProvider) {
                $routeProvider.when('/contractNumber/:contractNumbers', {
                    controller : 'ContractController',
                    templateUrl : './contractSearchResult',
                    reloadOnSearch : true
                }).when('/serialNumber/:serialNumbers', {
                    controller : 'SerialController',
                    templateUrl : './serialSearchResult'
                }).when('/QuoteManager',{
                    controller : 'QuoteManagerController',
                    templateUrl: './quoteManagerView'
                }).when('/QuoteManagerHome',{
                    controller : 'QuoteManagerController',
                    templateUrl: './quoteManagerHome'
                });
            });
    
            angular.bootstrap(document, ['ServiceContractModule']);
        });
    

    Check out angularAMD that I created to help the use of RequireJS and AngularJS: http://marcoslin.github.io/angularAMD/

提交回复
热议问题