Skip to content

Commit

Permalink
Merge pull request elastic#7976 from tsullivan/render-directive-contr…
Browse files Browse the repository at this point in the history
…oller-context

render directive: add controller context

Former-commit-id: 7b1ac98
  • Loading branch information
spalger authored Aug 10, 2016
2 parents a385326 + 81f4b53 commit 6153e7c
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/ui/public/render_directive/render_directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,24 @@ 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;

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: {
Expand Down

0 comments on commit 6153e7c

Please sign in to comment.