Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Directives got duplicated after an $animate.enter since beta.5 #8895

Closed
Foxandxss opened this issue Sep 2, 2014 · 7 comments
Closed

Directives got duplicated after an $animate.enter since beta.5 #8895

Foxandxss opened this issue Sep 2, 2014 · 7 comments

Comments

@Foxandxss
Copy link
Member

I got an issue where a directive was being created twice when I did some $animation.enter.

The issue started on my repo: Foxandxss/angular-toastr#18 so I started researching about it and the change was on beta.5 (when $animate.enter started to prepend instead of append).

I managed to reproduce it here: http://plnkr.co/edit/oYmXPIeN16g75a3kQJQc?p=preview

Starting from the console error (In my code I use enter like that and I get no error tho). Technically that shouldn't happen (I think).

Leaving that aside, you can see the directive twice on screen. If you change templateUrl to template it works (much like #6006).

So I was wondering if I did wrong on the plunker (adding a third parameter resolves the issue) or there is a bug.

@btford btford added this to the Backlog milestone Sep 3, 2014
@btford
Copy link
Contributor

btford commented Sep 3, 2014

@matsko any ideas?

@matsko
Copy link
Contributor

matsko commented Sep 3, 2014

This looks like it's a bug with the compiler / interpolation code. The prepending causes it to somehow recompile itself and loose track of the node order. @tbosch can you have a look?

@tbosch tbosch self-assigned this Sep 3, 2014
@tbosch
Copy link
Contributor

tbosch commented Sep 3, 2014

yes, will do

@tbosch tbosch assigned jeffbcross and unassigned tbosch Sep 10, 2014
@jeffbcross jeffbcross modified the milestones: 1.3.0-rc.2, Backlog Sep 10, 2014
@jeffbcross
Copy link
Contributor

After reviewing this with @tbosch we believe that the example should not be supported, as changing DOM within controllers is strongly discouraged. If the animation logic in the example were moved to the directive's postLink function, where DOM manipulations are permitted, the issues go away.

See updated example: http://plnkr.co/edit/KpFedIafuuPamEhtl5f0?p=preview

@tbosch
Copy link
Contributor

tbosch commented Sep 12, 2014

Here is an updated plunker that shows the effect even without ngAnimate: http://plnkr.co/edit/gfYEpxitqe4ohFzj7oFf?p=preview

The call to $animate.enter will essentially call body.prepend(container), which will then result in an error during the compile process (see dev tools). The fact that you see the template doubled is only a side effect of the error in the dev tools, which also occurs when you use an inline template (see the commented line in the plunker).

Yes @jeffbcross is correct in saying that you should not modify the DOM in the controller, especially as the controller constructor function is called in the prelink phase (see https://docs.angularjs.org/api/ng/service/$compile#pre-linking-function).

Closing this...

@tbosch tbosch closed this as completed Sep 12, 2014
@Foxandxss
Copy link
Member Author

@jeffbcross @tbosch The plunker is on a controller just for demo purposes. My real code is on a factory. It is a factory that generates directives (a factory to generate popup messages). There it happen too.

Well, I will workaround then.

@tbosch
Copy link
Contributor

tbosch commented Sep 12, 2014

Yes, but same reasoning there. You can also try to replace $animate.enter with body.prepend, just like I did in the example, and you should see the same error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants