A
A
Artem Shchurin2016-02-29 09:13:36
JavaScript
Artem Shchurin, 2016-02-29 09:13:36

Is it possible to get the $scope of a controller, from outside of angular?

Good afternoon!
Half of the application with which the question arose does not work in the context of angular, the other half uses reusable components in angular. There is a controller through which these 2 halves communicate.
That's what it's all about, inside one of the controllers (angular) the user changed a number of parameters, after which these parameters diverge among the active elements registered in the application (without angular), most of the elements have not yet been created, they are created by the user's action, as when creating an element, get the parameters that were changed in the controller (angular)?
I can cache when changing in a self-written controller, which is just doing the creation of new active elements, but there was an interest in how angular entities can be reached outside the context of its use, maybe. you can simply request the necessary data.
angular.module('name').controller('name');
For example, he called in the console, which received an object with angular methods and no hint of a controller or a reference to an instance, not to mention $scope inside.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-02-29
@schurin

It is probably better to store the data in some kind of factory.
You can access this factory via $injector.

var injector = angular.injector(['ng', '%имя вашего модуля%']);
var factory = injector.get('%имя вашей фабрики%');

But in general, it's absolutely terrible.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question