0

I'm working on a complex Angular app and I'd like to know if there is a proper way to load a controller file path in an ui-router.

Currently, I load every controllers file in the main view like this : <script src="myCtrl.js"></script>.

I know that I can use ui-router like this :

 $state provider
    .state('state1'), {
       url: '/state1',
       views : {
           'area1' : {
                        templateUrl: 'myView.html',
                        controller: 'myCtrlName' // change this to load the file ?
            },
            ... // some other area + templateUrl here
       }
    }

But it's used to load the controller name, not its path. I tried to find a way by using load or file functions instead, but it didn't make it.

Do you have any idea ?

Edit : Maybe it can help you to know thatmy goal is to load my controller file out of the html view in order to simplify the html file and simply add/delete controllers in the app.

Arhyaa
  • 369
  • 1
  • 3
  • 21
  • *Try to observe this http://stackoverflow.com/a/27754025/1679310 or that http://stackoverflow.com/a/27466890/1679310* – Radim Köhler Jun 03 '15 at 08:53
  • 2
    `.state('state1'),` should be `.state('state1', {` – Pepijn Jun 03 '15 at 08:53
  • So if i understand your case, you have one controllers per file ? In this case you have declared one module by controllers file so inject module in app.js and add your controller. – carton Jun 03 '15 at 08:55
  • @RadimKöhler I read that question. Isn't there an easier way ? – Arhyaa Jun 03 '15 at 08:56
  • check this out man https://github.com/angular-ui/ui-router – Olatunde Garuba Jun 03 '15 at 08:58
  • @Arhyaa Honestly I am not sure. But I would say NO, because all the runtime of angular, including UI-Router is expecting services, controllers to be loaded.. but maybe I missed some brand new feature... My way in fact is: load all controllers... their code (minimized) should not be an issue in fact... – Radim Köhler Jun 03 '15 at 08:58
  • @carton I have one module to declare every controller, and it seems to work. I use a file per controller, and they're not in the same folders. – Arhyaa Jun 03 '15 at 08:59
  • @generalgmt Thx man, but I've already read it. It didn't help me in the way I'm searchin' for – Arhyaa Jun 03 '15 at 09:00
  • If one module declavere every controller just add this module in your app.js and use controller: 'myCtrlName' (like your sample) – carton Jun 03 '15 at 09:00
  • @RadimKöhler OK, I'll try to use this. Thanks a lot :) – Arhyaa Jun 03 '15 at 09:01
  • *@Arhyaa, please, take is as a hint. Maybe I missed some brutal enhancment of angular ;) just a hint how to do that all with RequierJS ;)* – Radim Köhler Jun 03 '15 at 09:02
  • @carton I'm already doing this. What I want to simplify is the controller.js path load :) – Arhyaa Jun 03 '15 at 09:02
  • 1
    @RadimKöhler I've spent a week looking for another way, and I found nothing at all. It doesn't cost anything to try ;) – Arhyaa Jun 03 '15 at 09:04

1 Answers1

1

According to Radim Köhler and these questions angular-ui-router with requirejs, lazy loading of controller + AngularAMD + ui-router + dynamic controller name?, I'll try to use RequireJS.

Thanks a lot guys :)

Community
  • 1
  • 1
Arhyaa
  • 369
  • 1
  • 3
  • 21