6

在大型应用程序中,我们如何在需要时延迟加载模块、控制器、服务而不加载 index.html 中的那些。这里我指的是在相关的模板html中加载整个js,而不是在index.html中。(可能是具有模块、多个控制器、服务、给定功能的指令或具有多个控制器或服务的单个 js 文件的不同 js)

我不想使用 RequireJs。但是,我正在寻找角度本身的解决方案。

angular.module( 'my-second-module', ['ui.router'])

.config(function config($stateProvider) {
    $stateProvider
        .state('mainscreen', {
            url: "/mainscreen",
            templateUrl: "app/MyMain.tpl.html"
        })
        .state('mainscreen.sub', {
            url: "/sub",
            controller: 'subCtrl',
            templateUrl: "app/sub.tpl.html"
        })
})
.controller( 'subCtrl', function contractCtrl
    ($scope,$http,$route,$location) {
})
.controller( 'subTwoCtrl', function newContractCtrl($scope,someService,$http,$templateCache) {
.filter('myTypeFilter',function(){
    return function (input,value){       
        return 'Normal';
   };
})
.service('newService', function () {
    var selectedContract = [];
    var hotelObject=[{}];
    return {
        notes:function () {
        },
        addNote:function (noteTitle) {
        }
    };
})
.directive('autocomplete', function($parse) {
return function(scope, element, attrs) {
    var setSelection = $parse(attrs.selection).assign;
    scope.$watch(attrs.autocomplete, function(value) {
        element.autocomplete({
            source: value,
            select: function(event, ui) {
                setSelection(scope, ui.item.value);
                scope.$apply();
            }
        });
    });
};
})
.factory('restService', function(commonService) {
return {
    setReturnMessage: function(res) {
};
})
});
4

2 回答 2

0

After doing some research identified that AngularJs is planing to implement above concept in their version 2.0. However, I'm not sure when that version will be released and also there is a long way to go for this version to be released.

Further, after doing much more research found out that there is a framework called Browserify which will be the next replacement for RequireJS. I believe we can use this for the modularization. However, I have not experimented this with AngularJs. Seems to be a good tool.

This has been discussed in the ng-conf as well. Angular with Browserify

PS. If anybody had done testing with Angular and Browserify you are mostly welcome to share your experience.

于 2014-04-17T10:07:18.360 回答
0

一旦 Angular 团队发布了 Angular v2.0,它应该会容易得多,但同时你可以使用我的模块来延迟加载几乎任何东西:ocLazyLoad

如果您对此有任何疑问,请不要犹豫。

于 2014-04-29T08:49:34.397 回答