0

Currently I add my controllers in index.html with just a normal script tag like so

<script src="js/controllers/admin/languages.js"></script>

I was wondering if it's possible to to tell the state that I want to include this script so that I don't have to add all my controller script in the index.

.state('admin.languages', {
    url: '/languages',
    templateUrl: 'views/admin/languages.html'
})

This is what my state looks like now.

Thank you.

  • Are you trying to achieve something like [lazy loading](https://angular.io/docs/ts/latest/guide/ngmodule.html#!#lazy-load) ? Do you intend to use Angular 1.x or Angular 2 and above ? – Ankit Feb 09 '17 at 06:35
  • Might be helpful https://stackoverflow.com/questions/25168593/angularjs-lazy-loading-controllers-and-content – Ankit Feb 09 '17 at 06:38

1 Answers1

0

You can try to define a reslove that handles dynamically loading the script containing the target controller and resolve the promise once the load is complete :

.state('admin.languages', {
url: '/languages',
templateUrl: 'views/admin/languages.html',
resolve: resolveController('js/controllers/admin/languages.js')
})
Lotus91
  • 1,127
  • 4
  • 18
  • 31