0
votes

If I'm resolving a service in $routeProvider I can inject the service like this and return whatever I want to resolve.

templateUrl: '/static/views/myView.html',
controller: 'myCtrl',
resolve: {
    myResolution: function(myService) {
        return myService.promise;
}

But I am using a library dependency that gets initialized by a directive in the matching templateUrl. To clarify, a directive in myView.html causes the dependency to get initialized. And I'm injecting this into myCtrl for use there. But in the controller this dependency is null, so its not getting resolved properly.

How do I force angular to resolve this type of dependency before injecting it into my controller?

1

1 Answers

1
votes

That library should expose a way for you to pass in resolves or a similar way to wait for data (for example, the UI-Bootstrap library allows you to pass in things to resolve before a modal dialog shows). If the library doesn't allow this, then your myCtrl needs to $watch for the data that the dependency initialises, and only act on it once its available.