From 81f4b534ff245ce47e7851ff3dcf03037655efd4 Mon Sep 17 00:00:00 2001 From: Timothy Sullivan Date: Wed, 10 Aug 2016 11:53:37 -0700 Subject: [PATCH] render directive: add controller context Former-commit-id: da95f35283a803329bfcce6a6e57e2d1cfbcf439 --- src/ui/public/render_directive/render_directive.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ui/public/render_directive/render_directive.js b/src/ui/public/render_directive/render_directive.js index b9a65b828e795..19a9502262334 100644 --- a/src/ui/public/render_directive/render_directive.js +++ b/src/ui/public/render_directive/render_directive.js @@ -38,7 +38,7 @@ uiModules template: function ($el, $attrs) { return $el.html(); }, - controller: function ($scope, $element, $attrs, $transclude) { + controller: function ($scope, $element, $attrs, $transclude, $injector) { if (!$scope.definition) throw new Error('render-directive must have a definition attribute'); const { controller, controllerAs, scope } = $scope.definition; @@ -46,8 +46,16 @@ uiModules applyScopeBindings(scope, $scope, $attrs); if (controller) { - if (controllerAs) $scope[controllerAs] = this; - $scope.$eval(controller, { $scope, $element, $attrs, $transclude }); + if (controllerAs) { + $scope[controllerAs] = this; + } + + const locals = { $scope, $element, $attrs, $transclude }; + const controllerInstance = $injector.invoke(controller, this, locals) || this; + + if (controllerAs) { + $scope[controllerAs] = controllerInstance; + } } }, link: {