Answer the question
In order to leave comments, you need to log in
How to get a parent class variable from a child class?
I wrote an example in js and an example in angular5. In theory they should work the same, but in practice they don't work the same. Please help me find the reason.
There is a parent class and there is a child class. It usually happens that the child class sees all the variables of the parent class. BUT in this angular5 example, it turned out that the parent class sees the variables of the child. In the example, this can be seen from the console output.
I tried to reproduce the same situation in native javaScript, but I got an error (also visible in the console). This is what worries me
Answer the question
In order to leave comments, you need to log in
You obviously don't understand the mechanics of what's going on.
No, there is an extensible class (ancestor class) and a class that inherits properties and methods from the ancestor class (child class).
In your ancestor class, nothing from the descendant class is available, you made erroneous conclusions.
In fact, the ancestor component defines the ngOnInit method, which is inherited and called by the descendant component. Look , I changed your example and now you can see in the console who exactly calls ngOnInit
in your example.
And this is how you can reproduce, in fact, the same situation.
Urgently pull up the basics of JavaScript and the Angular API .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question