@@ -61,7 +61,7 @@ function mdCompilerService($q, $templateRequest, $injector, $compile, $controlle
61
61
* - `link` - `{function(scope)}`: A link function, which, when called, will compile
62
62
* the element and instantiate the provided controller (if given).
63
63
* - `locals` - `{object}`: The locals which will be passed into the controller once `link` is
64
- * called. If `bindToController` is true, they will be coppied to the ctrl instead
64
+ * called. If `bindToController` is true, they will be copied to the ctrl instead
65
65
* - `bindToController` - `bool`: bind the locals to the controller, instead of passing them in.
66
66
*/
67
67
this . compile = function ( options ) {
@@ -112,12 +112,19 @@ function mdCompilerService($q, $templateRequest, $injector, $compile, $controlle
112
112
link : function link ( scope ) {
113
113
locals . $scope = scope ;
114
114
115
- //Instantiate controller if it exists, because we have scope
115
+ // Instantiate controller if it exists, because we have scope
116
116
if ( controller ) {
117
- var invokeCtrl = $controller ( controller , locals , true , controllerAs ) ;
117
+
118
+ var ctrlLocals = angular . extend ( locals , {
119
+ $element : element
120
+ } ) ;
121
+
122
+ var invokeCtrl = $controller ( controller , ctrlLocals , true , controllerAs ) ;
123
+
118
124
if ( bindToController ) {
119
125
angular . extend ( invokeCtrl . instance , locals ) ;
120
126
}
127
+
121
128
var ctrl = invokeCtrl ( ) ;
122
129
//See angular-route source for this logic
123
130
element . data ( '$ngControllerController' , ctrl ) ;
0 commit comments