-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Rename $postLink
to $onLink
or $onPostLink
#14651
Comments
I assume it was done on purpose, but @petebacondarwin probably knows more. |
Significantly, there is no direct parallel for the We felt that given its tight alignment with the post link function and that we wanted to make it clear that this did not match anything in Angular 2 it should have this name. To be honest we couldn't really come up with any real use cases for it but added it for completeness. I am afraid that it would be a breaking change to rename this hook now so that is not going to happen. Other than aesthetic is there any functional reason why this should change? |
@petebacondarwin I've just started converting some Angular 1 directives to components, and I was also hoping to avoid having to use
And:
This lead me to assume that I should not have code like However, if you're saying:
Does that mean it's safe to do DOM manipulation and bind DOM event handlers in the Other than aesthetic reasons, no, I have no functional reason for it to change. Was just curious why the discrepancy was there. If I can avoid using it and only have |
I've actually just moved all |
DOM manipulation should be in post link but adding handlers should be fine in $onInit. But we felt that both of these things should be rare in components where the template is in charge of UI |
One use case I have for having to access the element in the component code is moving CSS classes from the component element to the parent element of the actual component HTML. This is necessary now that this.classes = $element[0].className;
$element[0].className = ''; I guess I could refactor the keydown handler to use |
I think how safe it is depends on the template content. If it contains directives that manipulate the DOM in their linking functions, There might be another (theoretical) advantage of having DOM-related functionality in a dedicated method (such as |
I think having the name different from the other lifecycle hook makes sense, based on the discussion here. |
Given these component lifecycle hooks, find the odd one out:
Why this discrepancy? Can we call the
$postLink
hook$onLink
or$onPostLink
to be consistent?The text was updated successfully, but these errors were encountered: