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

ngInclude compiles template even after scope is destroyed #13515

Closed
zgmnkv opened this issue Dec 11, 2015 · 2 comments
Closed

ngInclude compiles template even after scope is destroyed #13515

zgmnkv opened this issue Dec 11, 2015 · 2 comments

Comments

@zgmnkv
Copy link
Contributor

zgmnkv commented Dec 11, 2015

With slow internet connection template may load significant time. And scope may be destroyed before template is loaded (e.g. some section is hidden by user action).

ngInclude doesn't check whether scope is destroyed and compiles the template, that may lead to several problems:
Memory leak: compiled template and scope are never destroyed, destroy event will never fire.
If some directive inside ngInclude template requires parent directive from outside of ngInclude, it will throw a js error because outer directive is already destroyed.

The error occurs with angularjs 1.2.29 and 1.4.8.

Possible fix would be checking whether scope is not destroyed before compiling template or cancelling template load promise when scope is destroyed.

This plunker demonstrates the issue: http://plnkr.co/edit/20PSyn65ggL6FPYsLcJX
Ben Nadel also mentioned this issue in this post: http://www.bennadel.com/blog/2891-nginclude-asynchronous-template-life-cycle-bug-in-angularjs.htm

@Narretz
Copy link
Contributor

Narretz commented Dec 11, 2015

Thanks for the report. Would you like to submit a PR for this?

@zgmnkv
Copy link
Contributor Author

zgmnkv commented Dec 15, 2015

Yeah, I'm working on a PR

gkalpak pushed a commit that referenced this issue Dec 21, 2015
With slow internet connection scope may be destroyed before template is loaded.
Previously in this case ngInclude compiled template that leaded to memory leaks
and errors in some cases.

Closes: #13515
Closes: #13543
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

2 participants