Z
Z
zlodiak2018-05-19 10:25:07
Angular
zlodiak, 2018-05-19 10:25:07

Is it possible to call a hook from code?

Can you please tell me whether it is correct to make calls of this kind?
this.ngOnInit();
Here is a live demo.
Are there any reasons not to do so?
The console does not swear, but it feels like the script began to work more slowly.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-05-19
@zlodiak

Are there any reasons not to do so?

It is more appropriate to ask - is there any reason to do so? These are not known to me. If you want to re-execute some code from a hook at an arbitrary moment, put it in a separate method and call this method.
And what you showed as an example, when assigning a rating, you pull ngOnInit - is that the component reinitialized when the rating changes? No that's not true. Why then mislead yourself and those people who will read your code? Not just variables, methods, classes, etc. give human-readable names describing their purpose.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question