I have a page with multiple widgets. After the page loads I get a list of widgets which containes a url. I then ng-include the url.
Each widget has it's own controller, which is loaded using a <script> tag in the widget html. Since the widget list is dynamic, I can't load the widget .js files on page load. (when I do, it works fine.) I keep getting an error.
I'm trying to wrap the $http calls in a service to make my controller unit testable.
Here's my HTML:
<script src="/widget/fooWidget.js"></script>
<div ng-controller="FooWidgetCtrl">
...
</div>
And here's my fooWidget.js: (I have a Widgets module defined in a file that is loaded on page load)
Widgets.service('FooWidgetSvc', function($http) {
this.getSomething = function() {
// $http methods
}
});
function FooWidgetCtrl($scope, $http, FooWidgetSvc) {
FooWidgetSvc.getSomething();
return $scope.FooWidgetCtrl = this;
}
And I get the following error:
Error: Unknown provider: FooWidgetSvcProvider <- FooWidgetSvc
at Error (<anonymous>)
I expect that this is happening because I'm trying to define a service after the angular bootstrap process completes.
I can make a plunker if that helps.
UPDATE
Thanks for the responses so far. I have created a plunker to help illustrate my issue: http://plunker.co/edit/iKzwnlZ7bNDjmR05qGDC
I have figured out how to manually register a controller, and have included it in the plunker.