0

i am new in angularjs and javascript. my ngroute and ozlazyload runs successfully but only once.

SPLK.config(function ( $ocLazyLoadProvider, $routeProvider) {

$ocLazyLoadProvider.config({
    loadedModules: ['SPLK'],
    modules: [
                {
                    name: 'datatables-counsellorJS',
                    files: ['src/assets/demo/default/custom/crud/datatables/data-sources/ajax-server-side_.js', 'src/assets/vendors/custom/datatables/datatables.bundle.js'],     
                }
            ]
});

$routeProvider
    .when('/counsellor/', {
        templateUrl: 'view/counsellor.php',
        controller: 'counsellorCtrl',
        resolve: {

            loadModule: ['$ocLazyLoad', function ($ocLazyLoad) {


                return $ocLazyLoad.load('datatables-counsellorJS');
                        }]
        }
    })
    .when('/registration/', {
        templateUrl: 'view/registration.php',
        controller: 'regCtrl',
    })
    .when('/reports/', {
        templateUrl: 'view/reports.php',
        controller: 'reportsCtrl',
    })
    .when('/statistics/', {
        templateUrl: 'view/statistics.php',
        controller: 'statsCtrl',
    })
    .when('/preferences/', {
        templateUrl: 'view/preferences.php',
        controller: 'prefCtrl',
    })
    .when('/counsellordetails/', {
        templateUrl: 'view/counsellordetails.php',
        controller: 'counsellorDetailsCtrl',
    })
    .otherwise({
            templateUrl: 'view/dashboard.php',
            controller: 'dashboardCtrl',

        });

dashboard will be the landing page. if i click to /counsellor, the js can be loaded. but if i route to other links, and then click to /counsellor again, it does not work.

even i need to include both js in parent html.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Faizal Nor
  • 13
  • 1
  • 6
  • That should be the correct behaviour of oclazyload. It will load your template in the angularjs $templatecache and if the controller file isn't included already it will include it. Therefore it only need to be triggered once per route – MrWook Jun 27 '18 at 07:30
  • my datatables cannot be loaded for second visit. any suggestion? – Faizal Nor Jun 27 '18 at 08:00
  • Oclazyload is there to lazyload javascript files or other files into the application not to load you data on the filesystem everytime. If this data don't change you only should load it once inside the controller or in a service. You don't need to use the oclazyload.load inside the router. You can freely use it in any service. – MrWook Jun 27 '18 at 08:13

0 Answers0