0

I am working on a project with more 300+ pages based on AngularJS.

Everything is all right, but I'd like to find a way to get rid of those 300+ lines for routing.

Here my thoughts :

  1. User goes on url /settings/company
  2. AngularJS has to load templateUrl at '/template/'+settings/company+'.html'
  3. Then AnguarJS loads controller SettingsCompany+'Ctrl'

Do you think if it is possible ?

Jacques Cornat
  • 1,612
  • 1
  • 19
  • 34

1 Answers1

0

If you are using ui-router which I would recommend you can create your routes Dynamicly all you need to do is

var state = {
 url: someUrl
 template: someHtml
 controller: someController                                                
};

$stateProviderRef.state(TheStatename, state);

You obviously need to do that before loading the view. I personally have a static login in my app and after i know which user logged in i load different modules and with this i basicly create the states dynamicly and load the Controller files with lazyload.

Hope this was helpful

stackg91
  • 584
  • 7
  • 25
  • I've never tried ui-router, I am going to try, thanks for the help ! – Jacques Cornat Aug 27 '15 at 15:15
  • I forgot to mention you need to add StateProviderRef in you APP.js config – stackg91 Aug 27 '15 at 15:19
  • Like this ? [demo](http://plnkr.co/edit/IzimSVsstarlFviAm7S7?p=preview) (see app.js file) – Jacques Cornat Aug 27 '15 at 15:21
  • I think it was without config APP.stateprovider = stateproviderref sry cant explain better in my smartphone but you gonna find it with that – stackg91 Aug 27 '15 at 15:24
  • http://stackoverflow.com/questions/24727042/angularjs-ui-router-how-to-configure-dynamic-views check the first post in the middle somewhere plunkr is not really smartphone friendlY :( – stackg91 Aug 27 '15 at 15:33