ngInclude compiles template even after scope is destroyed #13515
Description
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