Sachin
Sachin

Reputation: 142

How to load dynamic JS in angular js?

app.config(function ($routeProvider,  $locationProvider) { $routeProvider.
       when('/login', {
           templateUrl: '/Login/_Login.aspx',
           controller: 'LoginCtrl'
       });
));

The LoginCtrl is in another JS File which is not loaded yet, So i will load that js so it work properly?

Upvotes: 0

Views: 36

Answers (1)

Durgpal Singh
Durgpal Singh

Reputation: 11953

$stateProvider
            .state('main', {
                url: '/main',
                templateUrl: 'templates/main/main.html',
                controller : 'mainController',
                resolve: {
                    loadReqFiles: ['$ocLazyLoad', function ($ocLazyLoad) {
                        return $ocLazyLoad.load([
                            'templates/main/main.css',
                            'js/controller/main.js',
                            'js/services/sessionService.js'
                        ]);
                    }]
                }
            })

read this for more information... LazyLoad

Upvotes: 1

Related Questions