preLink, DOM manipulation ... compositeLinkFn "TypeError: Cannot read property 'childNodes' of undefined" #2532
Description
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.