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.

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

Description

@prashantjain68

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.

Activity

  1. prashantjain68 commented on Apr 27, 2013

    @prashantjain68
    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

  2. prashantjain68 commented on Apr 29, 2013

    @prashantjain68
    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.

  3. btford commented on Aug 24, 2013

    @btford
    Contributor

    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions