AngularJS: lazy loading controllers and content

后端 未结 9 863
小鲜肉
小鲜肉 2020-12-02 19:00

In this simplified scenario, I have two files: index.htm, lazy.htm.

index.htm:

var myApp = angular.module(\'myApp\', []);
myApp.controller(\'embed\',         


        
9条回答
  •  旧时难觅i
    2020-12-02 19:32

    ////JConfig file--------

    window.angularApp.config(function ($routeProvider,$controllerProvider,$compileProvider,$provide, azMessages) {
    
    $routeProvider.when('/login', {
                 resolve: {
                     load: ['$q', '$rootScope', function ($q, $rootScope) {
                         var deferred = $q.defer();
                         require([
    
                             //load required Js file here
    
                    ], function () {
                        $rootScope.$apply(function () {
                            deferred.resolve();
                        });
                    });
                         return deferred.promise;
                     } ]
                 }
             });
    
    
      $routeProvider.otherwise({ redirectTo: '/login' });
    
        window.angularApp.components = {
            controller: $controllerProvider.register,
            service: $provide.service,
            directive: $compileProvider.directive
        }
    

    //contoller declaration

    angularApp.components.controller('DiscussionController',[function(){
    
    }]);
    

提交回复
热议问题