Guy Nesher
Guy Nesher

Reputation: 1385

Angular RouteProvider - resolve not passing object to controller

Take a look at the following plunker: http://plnkr.co/edit/uEbEdNifuBReENxzhb6H?p=preview

The expected behaviour for the routeProvider resolve (to my understanding) is for the resolved object to be injected into the controller. However Angularjs throws an "Unknown provider" error.

I have seen suggestions to inject the original service, but that will result in a deferred object, which renders the routeProvider resolve rather useless.

Upvotes: 3

Views: 4240

Answers (1)

joakimbl
joakimbl

Reputation: 18081

You should specify the controller with the root provider - not in the template (or the controller will be used regardless of the path, which may result in the dependencies not resolving):

$routeProvider.when('/',{controller:'TestCtrl', ...

I've updated your plunker: http://plnkr.co/edit/mSb58e8cGDNYU27xSizk?p=preview

Upvotes: 5

Related Questions