In AngularJS, I have two lengthy controllers, which are identical - except for one variable definition at the top (which is used in multiple places throughout the controller to decide what to process).
How can I consolidate these two controllers into only one controller?
Is there something like a controller factory that can take in an argument (my variable)?
Can you pass a variable to a controller, when specifying it in the router? Can you pass a variable when manually calling a controller via ng-controller in the html?
Something like this:
ControllerA
{
mode = 'A';
MakeControllerRealAndUseItInsteadOfCurrentController(mode);
}
ControllerB
{
mode = 'B';
MakeControllerRealAndUseItInsteadOfCurrentController(mode);
}
ControllerReal( mode )
{
mode = mode;
// actual controller content
}