Why the constructor is called again?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
19 views
There are two components. One inherits from another. Example here.

As you can see, the constructor of each outputs in console phrase. Please explain why the constructor of the component HelloComponent fulfills two times? It can be seen from the message in the console

This is the normal course of events, this can and should be avoided?
by | 19 views

1 Answer

0 like 0 dislike
@Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class HelloComponent extends AppComponent { // Here name = 'Angular 6'; constructor() { super(); // First console.log('...') console.log('constructor app'); } }


You AppComponent inherited from HelloComponent. To call super(). Then again shoved HelloComponent in the template:

 // Second console.log('...') Start editing to see some magic happen :) 
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked May 22, 2019 by vrazrabotchik
110,608 questions
257,187 answers
0 comments
40,796 users