I am developing an application in angular and I am creating components for different functionalities. The application consists of exercises to solve, and I want to create components with each of the functionalities.
I will place an example to make it easier to understand. I have created a component that when painted in html, is a true or false exercise. Every time I integrate it, the same questions always appear, and my intention is that those questions change every time I integrate it.
I have thought of passing a parameter to the component of an object type variable so that through it it paints what is necessary.
here the html
<app-trueOrFalse objeto=[objeto]></app-trueOrFalse>
And here the example object in typescript
ngOnInit(): void {
let objeto1 :{
"preguntas": [
"pregunta1", "pregunta2", "pregunta3"
],
"respuestas":[
true, false, true
]
}
}
This is the best way that has occurred to me, creating different objects for the different TrueOrFalse that I create, but I don't know if there is a better way to do this.
All the best
You could receive parameters in the component that you reuse to change the questions like this:
In your .ts file (of the component you are going to reuse) put the following:
Now when you call the component in your .html file you send the list of questions you want to display as follows: