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

preLink, DOM manipulation ... compositeLinkFn "TypeError: Cannot read property 'childNodes' of undefined" #2532

Closed
prashantjain68 opened this issue Apr 27, 2013 · 3 comments

Comments

@prashantjain68
Copy link

In one of my directives, in the preLink function I manipulate the DOM (element itself) and its children and descendants.

  • I add attributes to child elements.
  • I remove some children and may be their children.

Later, in the compositeLinkFn, I get the above error.
I also noticed, that if I do the same thing (remove children) in the postLinkFn, I get no errors.

Question: Is this by design (not be able to remove the children in the preLink) or is this a bug. I thought, preLink was supposed to let you manipulate the DOM any way you want.

Is there a way, I can do whatever I want with the DOM before the real compile starts. Something like a preCompile which starts from parent. OR I think there should be a capturePhase compile which goes top-down. In this phase, the compiler would have no knowledge of any descendants and the DOM can be easily manipulated.

@prashantjain68
Copy link
Author

Update: Seems like, I would do the DOM manipulation (including removing children) in the compile function.

Please confirm and close the bug.

Thanks
Prashant

@prashantjain68
Copy link
Author

Update 2: I cannot manipulate the DOM or child DOM if transclude = true. I still think, the directive should be able to manipulate the DOM before the link/compile phase.

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

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

No branches or pull requests

2 participants