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

Support modifying the DOM structure in link function of a directive #1773

Closed
wants to merge 2 commits into from

Conversation

mprobst
Copy link
Contributor

@mprobst mprobst commented Jan 8, 2013

Support modifying the DOM structure in the post link function of a directive by creating a defensive copy of the node list, as opposed to a live DOM list.
This is useful for directives to actually replace their entire DOM fragment, e.g. with the HTML fragment generated by a 3rd party component (Closure, Bootstrap ...). Closure doesn't support attaching to an existing DOM fragment easily (decorate always recursively walks the tree, instantiating additional components and performing unwanted DOM changes).
The workaround is to have Closure .renderSibling() its component and then move the content that's controlled by Angular into the component. To achieve that, Angular must support linking functions changing the DOM, which this patch implements.
Also fix the indentation of the compileNodes function (was one too little).

…rective by creating a defensive copy of the node list, as opposed to a live DOM list.

This is useful for directives to actually replace their entire DOM fragment, e.g. with the HTML fragment generated by a 3rd party component (Closure, Bootstrap ...).
Fix the indentation of the compileNodes function (was one too little).
}));
});
inject(function($compile, $rootScope) {
element = jqLite('<div><div remove-node></div><div>{{test}}</div>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be missing a closing </div> tag

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for spotting.

@IgorMinar
Copy link
Contributor

landed as cdf6fb1

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

Successfully merging this pull request may close these issues.

4 participants