0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.