Skip to content

Commit

Permalink
Preserving Controller Directives
Browse files Browse the repository at this point in the history
  • Loading branch information
teropa committed Apr 27, 2015
1 parent 903d1c0 commit ca8fe12
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function $CompileProvider($provide) {
var newScopeDirective;
var newIsolateScopeDirective = previousCompileContext.newIsolateScopeDirective;
var templateDirective = previousCompileContext.templateDirective;
var controllerDirectives;
var controllerDirectives = previousCompileContext.controllerDirectives;

function getControllers(require, $element) {
if (_.isArray(require)) {
Expand Down Expand Up @@ -447,6 +447,7 @@ function $CompileProvider($provide) {
{
templateDirective: templateDirective,
newIsolateScopeDirective: newIsolateScopeDirective,
controllerDirectives: controllerDirectives,
preLinkFns: preLinkFns,
postLinkFns: postLinkFns
}
Expand Down
32 changes: 32 additions & 0 deletions test/compile_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,38 @@ describe('$compile', function() {
});
});

it('sets up controllers for all controller directives', function() {
var myDirectiveControllerInstantiated, myOtherDirectiveControllerInstantiated;
var injector = makeInjectorWithDirectives({
myDirective: function() {
return {
controller: function MyDirectiveController() {
myDirectiveControllerInstantiated = true;
}
};
},
myOtherDirective: function() {
return {
templateUrl: '/my_other_directive.html',
controller: function MyOtherDirectiveController() {
myOtherDirectiveControllerInstantiated = true;
}
};
}
});
injector.invoke(function($compile, $rootScope) {
var el = $('<div my-directive my-other-directive></div>');

$compile(el)($rootScope);
$rootScope.$apply();

requests[0].respond(200, {}, '<div></div>');

expect(myDirectiveControllerInstantiated).toBe(true);
expect(myOtherDirectiveControllerInstantiated).toBe(true);
});
});

});

});

0 comments on commit ca8fe12

Please sign in to comment.