marcoslin / angularAMD

Facilitate use of RequireJS in AngularJS
http://marcoslin.github.io/angularAMD
MIT License
734 stars 171 forks source link

Support for controllerProvider in ui-router #117

Closed MarkJPerry closed 9 years ago

MarkJPerry commented 9 years ago

I have a need to use the controllerProvider overload when configuring routes in ui-router using AngularAMD but I notive that only controller and controllerUrl are supported.

Would it be possible for you to load both the controller and controllerUrl from the controllerProvider result which is a string specifying the controllername?

This way I can configure my application thusly:

.state('customState',
  angularAMD.route({
    url: '/:parent/:child',
    templateUrl: function($stateParams){
      return '/templates/' + $stateParams.parent + '/' + $stateParams.child;
    },
    controllerProvider: function($stateParams){
      return $stateParams.parent + '-' + $stateParams.child;
    }
  })
)

If I am reading the source code correctly (and I may not be) you are using the AngularAMD requireJs wrapper to load the controller dynamically then pass through to angular. I couldn't find any reference to controllerProvider in the source.

marcoslin commented 9 years ago

controllerProvider seems to be very ui-router specific implementation so I would prefer not do anything specific within angularAMD. Here is a solution to your question:

http://stackoverflow.com/questions/27465289/angularamd-ui-router-dynamic-controller-name/27466890#27466890

Having said that, having controllerUrl support a function might make things a lot easier for you. I close this one and add an enhancement for next release.

MarkJPerry commented 9 years ago

Thank you for the link that's exactly what I was looking for. Apparently my google fu failed me this time.

sayakb commented 9 years ago

@MarkJPerry Rather, I asked that question on stackoverflow after I saw your issue here :)