In my non-angular code I am getting controller object through following code
var controllerElement = angular.element('[ng-controller="' + controllerName + '"]');
var controller = controllerElement.controller();
It was working perfectly until day before yesterday when instead of controller object controller object has some $get.h {}
Following code returns correct controller object but there is a scenario in which angular is throwing exception:
var $controller = injector.get("$controller");
var controller = $controller(controllerName, { $scope: scope });
Could you please help me find figure out what is the problem with former approach i.e. controllerElement.controller();
EDIT: Found another issue with latter approach that it instantiates a new controller object instead of returning the original one associated with the element.
controllerElement.length