aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ng/compile.js4
-rw-r--r--test/ng/compileSpec.js38
2 files changed, 41 insertions, 1 deletions
diff --git a/src/ng/compile.js b/src/ng/compile.js
index 59a70145..d0b6e749 100644
--- a/src/ng/compile.js
+++ b/src/ng/compile.js
@@ -819,7 +819,9 @@ function $CompileProvider($provide) {
originalWidgetNode = tElement[0],
asyncWidgetDirective = directives.shift(),
// The fact that we have to copy and patch the directive seems wrong!
- syncWidgetDirective = extend({}, asyncWidgetDirective, {templateUrl:null, transclude:null}),
+ syncWidgetDirective = extend({}, asyncWidgetDirective, {
+ controller: null, templateUrl: null, transclude: null
+ }),
html = tElement.html();
tElement.html('');
diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js
index 1aef24fe..54837bf7 100644
--- a/test/ng/compileSpec.js
+++ b/test/ng/compileSpec.js
@@ -1692,7 +1692,45 @@ describe('$compile', function() {
element = $compile('<div c1 c2><div dep></div></div>')($rootScope);
expect(log).toEqual('dep:c1-c2');
});
+ });
+
+ it('should instantiate the controller just once when template/templateUrl', function() {
+ var syncCtrlSpy = jasmine.createSpy('sync controller'),
+ asyncCtrlSpy = jasmine.createSpy('async controller');
+
+ module(function($compileProvider) {
+ $compileProvider.directive('myDirectiveSync', valueFn({
+ template: '<div>Hello!</div>',
+ controller: syncCtrlSpy
+ }));
+ $compileProvider.directive('myDirectiveAsync', valueFn({
+ templateUrl: 'myDirectiveAsync.html',
+ controller: asyncCtrlSpy,
+ compile: function() {
+ return function() {
+ }
+ }
+ }));
+ });
+
+ inject(function($templateCache, $compile, $rootScope) {
+ expect(syncCtrlSpy).not.toHaveBeenCalled();
+ expect(asyncCtrlSpy).not.toHaveBeenCalled();
+
+ $templateCache.put('myDirectiveAsync.html', '<div>Hello!</div>');
+ element = $compile('<div>'+
+ '<span xmy-directive-sync></span>' +
+ '<span my-directive-async></span>' +
+ '</div>')($rootScope);
+ expect(syncCtrlSpy).not.toHaveBeenCalled();
+ expect(asyncCtrlSpy).not.toHaveBeenCalled();
+
+ $rootScope.$apply();
+
+ //expect(syncCtrlSpy).toHaveBeenCalledOnce();
+ expect(asyncCtrlSpy).toHaveBeenCalledOnce();
+ });
});
});