2

I have a dialog I want to use in two different places, so I've built a template and a controller trackCtrl for a modal to use. That controller is defined on the settingsApp module which is not the one launching the modal, so I would like to do something like this:

var modalInstance = $modal.open({
     templateUrl: 'templates/track.html',
     controller: 'settingsApp.trackCtrl'
});

but it fails of course.

What is the best way to solve this problem?

thanks!

4
  • You simply use the name of the controller, whatever its module is. At runtime, all the components are in the same namespace, whatever the module is. Commented Oct 26, 2014 at 14:29
  • I've got the following error: "Error: [ng:areq] Argument 'trackCtrl' is not a function, got undefined" Commented Oct 26, 2014 at 14:57
  • 1
    Then the controller is not named 'trackCtrl', or it's not defined at all, or its module is not loaded. Hard to help without seeing the code. Commented Oct 26, 2014 at 14:59
  • The problem was that the js containing the controller's registration was not called. Thanks! Commented Oct 26, 2014 at 15:09

2 Answers 2

1

Just add a dependency to your other module and then just simply use that controller name.

angular('app', ['settingsApp']);

var modalInstance = $modal.open({
     templateUrl: 'templates/track.html',
     controller: 'trackCtrl'
});
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I guess in most cases it would work, but it doesn't work in my project. I've paused on debug right before $modal.open command and angular.module("settingsApp") exists and reachable. any other suggestions?
0

The problem was that the js file defining the controller was never run. (The controller should be referred to simply by its name.)

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.