0

I have an application with 10 views and several shared components

--app
-------components
-------------home
-----------------homeController.js
-----------------homeDirective.js
-----------------home.html
 .
 .
 .
-------shared
----------modals
------------someModal
--------------- someModalController.js
--------------- someModal.html

the components load by angular routing

(function() {

    'use strict';

    angular
        .module('app')
        .config(appConfig);

    function appConfig($routeProvider) {
        $routeProvider.
        when("/home", { templateUrl: "app/components/home/home.html", controller: 'homeController' })............
        otherwise({ redirectTo: "/home" });
    }
})();

the modals used in different components , all things are worked when the main page contains all script files. for example

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

</head>

<body ng-app="fleetCam" ng-controller="appController">
    <div id="wrapper">

    <div id="page-wrapper">
        <ng-view>
        </ng-view>
    </div>
</div>
<!-- /#wrapper -->

<!-- jQuery -->
<script src="Scripts/jquery-2.1.4.min.js"></script>
<script src="Scripts/angular.js"></script>
<script src="Scripts/angular-route.js"></script>
<script src="Scripts/ngStorage.js"></script>



<script src="appMain/app.module.js"></script>
<script src="appMain/app.routes.js"></script>
<script src="appMain/app.services.js"></script>
<script src="appMain/app.directive.js"></script>


 <script src="appMain/components/home/homeController.js"></script>
   <script src="appMain/components/home/aboutController.js"></script>
   <script src="appMain/shared/modal/insert/insertController.js"></script>

I looking for a way to remove the last three script tags and load controller or other dependencies on the fly. I have searched a lot about lazy loading but no one works in my context especially when I add shared components.

3
  • angularAMD is one of the option Commented Oct 26, 2015 at 19:24
  • You could think of using github.com/ocombe/ocLazyLoad Commented Oct 26, 2015 at 19:42
  • @PankajParkar I think that's my solution Commented Oct 27, 2015 at 20:27

1 Answer 1

1

You could use the patterns from the async section on the official angular-seed repo: https://github.com/angular/angular-seed/#loading-angular-asynchronously

https://github.com/angular/angular-seed/blob/master/app/index-async.html

this relies on the ded/script "Async JavaScript loader & dependency manager" https://github.com/ded/script.js

Sign up to request clarification or add additional context in comments.

1 Comment

by this way I should reference all dependency in the main page explicitly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.