From 6ba09e34b4ed9d30c1e1c69dec1277a883f3e39a Mon Sep 17 00:00:00 2001 From: Kuba Walinski Date: Tue, 13 Jan 2015 11:43:30 +0100 Subject: [PATCH 1/2] Fix merging of two ngIfs in replace mode. --- src/ng/compile.js | 9 ++++++++- test/ng/directive/ngIfSpec.js | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 7b2dde884926..03b78771827c 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -2119,7 +2119,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { forEach(dst, function(value, key) { if (key.charAt(0) != '$') { if (src[key] && src[key] !== value) { - value += (key === 'style' ? ';' : ' ') + src[key]; + var concatString = ' '; + if(key === 'style') { + concatString = ';' + } + if(key === 'ngIf'){ //if ngIf is merged both conditions need to be taken into account + concatString = ' && '; + } + value += concatString + src[key]; } dst.$set(key, value, true, srcAttr[key]); } diff --git a/test/ng/directive/ngIfSpec.js b/test/ng/directive/ngIfSpec.js index 9ee94c95b55b..ad809e46f0ae 100755 --- a/test/ng/directive/ngIfSpec.js +++ b/test/ng/directive/ngIfSpec.js @@ -212,6 +212,23 @@ describe('ngIf and transcludes', function() { }); }); + it('should allow using ngIf on the target element and on the root element of the directive template when used in a replace mode', function() { + module(function($compileProvider) { + var directive = $compileProvider.directive; + directive('example', valueFn({ + template: '
guacamole
', + replace: true + })); + }); + inject(function($compile, $rootScope) { + $rootScope.innerCondition = true; + $rootScope.outerCondition = true; + var element = $compile('
')($rootScope); + $rootScope.$apply(); + expect(element.text()).toBe('guacamole'); + dealoc(element); + }); + }); it('should use the correct transcluded scope', function() { module(function($compileProvider) { From cb38c5cf805d8e997c9249ed52616861549c8e68 Mon Sep 17 00:00:00 2001 From: Kuba Walinski Date: Tue, 13 Jan 2015 16:19:46 +0100 Subject: [PATCH 2/2] Correct code style following jshint's suggestions. --- src/ng/compile.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 03b78771827c..df0bc4749660 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -2120,10 +2120,10 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { if (key.charAt(0) != '$') { if (src[key] && src[key] !== value) { var concatString = ' '; - if(key === 'style') { - concatString = ';' + if (key === 'style') { + concatString = ';'; } - if(key === 'ngIf'){ //if ngIf is merged both conditions need to be taken into account + if (key === 'ngIf') { //if ngIf is merged both conditions need to be taken into account concatString = ' && '; } value += concatString + src[key];