I wonder if that\'s a bug or documented somewhere. Seems like injecting $element into controller attached by ng-view directive fails. Here\'s an example:
script.js:
MainCtrl was injected by the $compile service which provides $element as a local. BookCtrl was injected by ngRoute which doesn't provide $element as a local. For more information on $compile injected locals, see AngularJS $compile API Reference -- controllers.
The locals that ngRoute injects are $scope, $template, and the other properties of the $resolve map.
ngRoute Docs:
localsA map of locals which is used by $controller service for controller instantiation. The
localscontain the resolved values of theresolvemap. Additionally thelocalsalso contain:
$scope- The current route scope.$template- The current route template HTML.The
localswill be assigned to the route scope's$resolveproperty. You can override the property name, usingresolveAsin the route definition. See $routeProvider for more info.
-- AngularJS ngRoute $route API Reference
$compile Docs:controller
Controller constructor function. The controller is instantiated before the pre-linking phase and can be accessed by other directives (see require attribute). This allows the directives to communicate with each other and augment each other's behavior. The controller is injectable (and supports bracket notation) with the following locals:
$scope- Current scope associated with the element$element- Current element$attrs- Current attributes object for the element$transclude- A transclude linking function pre-bound to the correct transclusion scope:
-- AngularJS Comprehensive Directive API - controller