Setting up scope inside a service?

I have a popup inside a service - its is called from another function in the same service to ask the user to select something. There is no access to $scope and there is no controller, so Im wondering how to pass dynamic data into the popup template? Does anyone have example code of creating an isolated scope and destroying it afterwards?

Well services aren’t meant to have direct access to a scope. thats what differences them from a controller.
Why not pass the data you need for your popup from the controller to your service, when you call that services function?

Im responding to an event, so there is no ‘controller’ and the event handler is encapsulated in a service. Or maybe there’s another way to get an array of data into the popup template?

Im currently creating an isolated local scope, assigning variables into it and then passing it into the popup’s scope: parameter, i.e.:

scope = $rootScope.$new(true);

And then Im destroying it later when the popup is closed:


Im just not sure if this is a good or bad way to deal with having no $scope available or if there’s a better way.

Mhh, not really sure what you want to do. Can you provide an example snippet on codepen or something, cause there are plenty ways to do this.

I would think that making a controller specifically for the pop up and assigning it in the template of that popup would be ideal. You can then add all the logic for buttons, set callbacks, or whatever you need via that controller. Controllers can be nested, it’s really handy.