← 输入框|github.com|刷新
Skip to content

docs: life-cycle - directives support "VIEW" lifecycle hooks, the docs say they dont #10221

Closed

Description

@shlomiassaf

I'm submitting a ... Hard to say....

Current behavior

  • ngAfterContentInit
  • ngAfterContentChecked
  • ngAfterViewInit
  • ngAfterViewChecked

Fire on directives.

Expected/desired behavior
According to the docs these lifecycle hooks are Components only

  • ngAfterContentInit
  • ngAfterContentChecked
  • ngAfterViewInit
  • ngAfterViewChecked

The compiler registers them to invoke on directives as well.
The view factory of a component containing a directive will invoke the lifecycle hook on that directive. This is not by change, this is by intent from the compiler as it requires accessing the directive instance and calling the hook within the detectChangesInternal method.

Here's a plunker
I can only assume the docs are incorrect...

Activity

  1. added
    area: core
    on Oct 4, 2016
  2. tbosch commented on Oct 4, 2016

    @tbosch
    Contributor

    ngAfterContentInit/Checked is also valid for directives, as they can also use @ContentChildren -> docs need to be changed.

    ngAfterViewInit also fires for directives so that they can be notified when all components in the template that they are in have been processed.

  3. removed
    area: core
    on Oct 4, 2016
  4. added
    area: core
    on Oct 5, 2016
  5. added
    open for contributions
    and removed
    area: core
    on Oct 6, 2016
  6. vicb commented on Oct 6, 2016

    @vicb
    Contributor

    Anybody from the community wants to submit a docs PR ?
    @shlomiassaf ?

  7. added a commit that references this issue on Nov 17, 2016
    4be9255
  8. Drumarcco commented on Nov 17, 2016

    @Drumarcco
    Contributor

    @vicb PR submitted 😃

  9. DzmitryShylovich commented on Feb 3, 2017

    @DzmitryShylovich
    Contributor
  10. 4 remaining items

  11. changed the title [-]Directives support "VIEW" lifecycle hooks, the docs say they dont[/-] [+]docs: life-cycle - directives support "VIEW" lifecycle hooks, the docs say they dont[/+] on Jun 23, 2017
  12. sandangel commented on Nov 7, 2017

    @sandangel

    5 months to process a docs fix PR ??? And it hasn't been merge yet.

  13. added a commit that references this issue on Nov 23, 2017
    8c72579
  14. added a commit that references this issue on Feb 21, 2018
    612cfec
  15. angular-automatic-lock-bot commented on Sep 13, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  16. locked and limited conversation to collaborators on Sep 13, 2019
  17. added a commit that references this issue on Jul 14, 2026
    b42921b
  18. added a commit that references this issue on Nov 20, 2026
    9b2f072
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

    freq1: lowopen for contributions

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions