Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
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

Description

@zgmnkv

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions