Merge pull request #7976 from tsullivan/render-directive-controller-context

render directive: add controller context
This commit is contained in:
Spencer 2016-08-10 13:19:02 -07:00 committed by GitHub
commit 7b1ac9884d

View file

@ -38,7 +38,7 @@ uiModules
template: function ($el, $attrs) { template: function ($el, $attrs) {
return $el.html(); 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'); if (!$scope.definition) throw new Error('render-directive must have a definition attribute');
const { controller, controllerAs, scope } = $scope.definition; const { controller, controllerAs, scope } = $scope.definition;
@ -46,8 +46,16 @@ uiModules
applyScopeBindings(scope, $scope, $attrs); applyScopeBindings(scope, $scope, $attrs);
if (controller) { if (controller) {
if (controllerAs) $scope[controllerAs] = this; if (controllerAs) {
$scope.$eval(controller, { $scope, $element, $attrs, $transclude }); $scope[controllerAs] = this;
}
const locals = { $scope, $element, $attrs, $transclude };
const controllerInstance = $injector.invoke(controller, this, locals) || this;
if (controllerAs) {
$scope[controllerAs] = controllerInstance;
}
} }
}, },
link: { link: {