Hello Folks ! I am new with Angular and I am a bit confused about binding.
So I saw that it serve to link parent/ Children property to share to the children the properties via signals/ @Input, right ?
but I am a bit confused. On my tutorial the dev create an object in TS to define the properties of a "Monster" Object.
a playing-card is the "children" component as the app is the parent component
app --> Playing-card
the future purpose is to create severals differents Playing-card. (Each one a different Monster)
- so Monster properties are typed in Monster.model.ts (an extern file in app folder)
- in Playing-cards.ts the Monster object is instantiated in the component class
- in app.ts
export class App {
monster1!: Monster;
constructor(){
this.monster1 = new Monster();
this.monster1.name = "Pik"
this.monster1.hp = 40;
this.monster1.figureCaption = "N°004"
}
and in app.html:
<div id="card-list">
<app-playing-card/>
<app-playing-card [monster] = "monster1"/>
</div>```
So I guess after in order to create several cards a JSON will be used and we just need to use a for loop in the app.html or in the constructor of the app class.
But I am not sure to understand everything:
- What is the binding definition with the [] around the property in the app html ?
- I am a bit confused with the TS why should we instantiated in the app constructor a monster1 ?
- how is working the compilation as I declare an App class with a constructor ? the constructor allow to create the monster each time App is instantiated but when should App be instantiate ? when the DOM is generated ?
I miss the point.
Why in playingCard.ts so my card component I have to instantiate also a new Monster ?
```ts
export class PlayingCard {
@Input() monster : Monster = new Monster();
}```
Thanks in advance for your feedback.
Sorry it's a bit the mess... 😅