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.

Controllers hooks order ($onChanges called before $onInit) #15515

@clemgrim

Description

@clemgrim

Do you want to request a feature or report a bug?
I dont know if it's wanted or if it's a bug

What is the current behavior?
First $onChanges call is done before the $onInit one.
With angular 1.6 default configuration (preassign = false), it's prefearable to initialize controller states in the $onInit function, given the bindings are not accessible yet in the constructor.

What is the expected behavior?
I think it would be more logical to call $onInit first.
Angular shouldnt do anything while the controller is not fully initialized.

What is the motivation / use case for changing the behavior?
If we use objects that are supposed to be created in the $onInit function in $onChanges function; we'll have an error in the first call, because the controller has not been initialized yet.
A solution could be to initialize those objects inside the constructor, but we'll initialize the controller in two different places...

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
angular 1.6 version

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions