-
Notifications
You must be signed in to change notification settings - Fork 27.5k
ngIf with replace:true on directive template #9837
Comments
Hi, @caitp could you help us on this one? ;-) |
since you asked nicely ^^ |
so, you can work around this by not using an element transclusion directive as the root element of the template --- I'm not sure exactly why this worked in beta 10 though, doesn't make a lot of sense. Lets dig through the changelog and see if it's listed in any of the breaking changes |
@petebacondarwin there are no breaking changes for $compile in beta 11, i think we forgot to add them |
I wonder if we could make this more palatable --- like, if you have element transclusion at the root of a replacement template, it should add the original parent scope in a custom data field, and use that when getting the parent scope. |
Thank you for your help about this! I knew your advice would be useful! ^^ We would definitely love to see a breaking change in the changelog and a new palatable behavior of angular in this use case. We hesitate between removing replace:true and avoid using element transclusion directive as root element. |
Ok so I added another exemple in the jsbin with a use case where the ng-if is not on the root element of the directive: |
seeing this as well, since upgrading to 1.3.1. my template is template = '<div class="tab-content" ng-if="visible">' +
'<div ng-if="tab" class="tab-inner-content clearfix" ng-include="tab"></div>' +
'</div>'; and it broke |
OK so someone need to propose a breaking change for this but where should we document this ? in ngIf doc ? in directive doc ? in changelog ? |
Only just seen this one. Let me take a look this week. |
I had this issue too. It seems to work if you wrap the root element (with the ngIf) in a new element (without ngIf) - as a temporary fix. |
Moving to 1.3.4 as I suspect that this is going to be a tricky fix (and not something that can be knocked up and suitably reviewed by Monday). |
Hi, has there been any progress on this, @petebacondarwin ? |
Directives that do replace cause so many problems. Given that we can almost always work around it with non-replace directives, I am going to move this to the Ice Box for now. |
Is there any way to detect this and throw a warning? I understand all the reasons to not fix and to deprecate replace... But as far as migrating an existing project this is a breaking change that isn't documented. We are migrating large apps that happened to have used replace: true and its difficult to know where we might have used transclusion. If we could at least identify or warn we could go and fix the replace attribute. Right now trying to replace every single directive across many apps would be quite difficult. |
@thetrevdev - as a start you could do a search of your code base for directives that employ |
Thats pretty difficult to do with a very large app. https://github.com/angular/angular.js/blob/master/src/ng/compile.js#L2104 |
@thetrevdev - glad you have got something working for you. If it turns out to be very helpful perhaps you could submit a patch? |
I think that this may be fixed by #12975 |
I think I'm still seeing this issue on v1.4.8. My directive had |
Also still experiencing this issue. I will look at avoiding |
@adambuczynski - other than CSS that is too constraining, are there any other reason why this is a pain? |
@petebacondarwin Yeah, CSS was one of the initial pains I ran into, but it was late at night and today's a new day, so it might turn out not as bad as I originally thought! :) There are a few other reasons I identified yesterday thought, one is that we need to apply an In order to not have to put the Second, to avoid repetition we also apply some classes to the parent element via the directive (via attributes on the directive's template). These get merged nicely now with any classes that are applied to the directive element in the main template. With Anyway, I only found out that Will report back after I've had another good look at it today, and see if I can work around them while not using |
@adambuczynski - be aware that though |
Thanks, yes I got that form reading more about it. I do intend to migrate to Angular 2 sooner rather than later, so figuring out now how to best use non-replacing directives would be the right step to take. To be honest though, I don't think wanting to apply |
It may not be "corner" but for sure it is "difficult". I haven't seen any PRs offering to fix it :-) |
@petebacondarwin Well, most directives I was able to convert painlessly, but there were the couple where some CSS tweaks were necessary. As for the one with the Do Angular 2 components offer a way to apply directives and other attributes on to the parent element via the directive templates? Because that currently seems to be the biggest drawback in Angular 1 directives, when not using |
It took me awhile to figure out I had this issue. I spent a fair amount of time assuming I had some sort of error in my scope configuration. It was only on a whim that I removed ng-if from the root element and discovered this to be the problem. It would be good to have some sort of warning. |
Just spent several hours trying to figure out what was wrong with my code to finally narrow it down to the |
Hello team,
We have a regression with the last angular version (since v1.3.0-beta.11)
In this commit d71df9f#diff-1c8fbee1402a2ef3c203def41d1960cdR97, you modified the child scope ngIf uses. Now with this modification, using ngIf on the root element of a directive template that is configured with
replace:true
, the $scope is not the expected one. (it's not the same)We tried to build a reduced test case to show the regression :
As you can see, the first directive failed in beta 11.
What do you think ? Is it a bug or the new expected behaviour ?
If so, maybe we should detail the documentation.
thx!
The text was updated successfully, but these errors were encountered: