curiouswebster
asked on
Angular: Need to set the id value (I think)
Code snippet from PuzzleCanvasComponent where I fill the PuzzlePieceComponent array.
I want to set the "id" property there, but this line does nothing:
this.pieces[index].id=inde x;
So I tried to use the HTML template for PuzzleCanvasComponent, but have the syntax wrong.
with the following properties created in the TS file
I'd prefer if the first method could be made to work, especially since I want to expand the number or properties set in
ngOnInit() beyond just the id.
Is method #1 fixable? Or must iI use the second method? If so, what is the syntax?
ngOnInit() {
let index = 0;
for(let row = 0; row < this.rows; row++) {
for(let column = 0; column < this.columns; column++) {
this.pieces[index] = new PuzzlePieceComponent();
this.pieces[index].id=index;
index++;
}
}
}
I want to set the "id" property there, but this line does nothing:
this.pieces[index].id=inde
So I tried to use the HTML template for PuzzleCanvasComponent, but have the syntax wrong.
<div class="puzzle">
<puzzle-piece *ngFor="#piece of pieces; #i=index" [value]="piece" [id]="i"></puzzle-piece>
</div>
with the following properties created in the TS file
export class PuzzlePieceComponent implements OnInit {
@Input() value:PuzzlePieceComponent;
@Input() id:Number;
...
I'd prefer if the first method could be made to work, especially since I want to expand the number or properties set in
ngOnInit() beyond just the id.
Is method #1 fixable? Or must iI use the second method? If so, what is the syntax?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER