Issue
I am a developing an ionic game, How can i get the properties of a child component(app-square) in a method in the parent component(app-board). app-board as over 30 app-square components, so i want it to be able to dynamically access it board-component.html(parent)
<app-square (click)="makeMove(l1)" [count]="3" #l1></app-square>
<app-square #l2></app-square>
board-component.ts
makeMove(obj: SquareComponent){
//I want to change the value of l2 here
}
I understand i cannot use ViewChild as it doesn't work inside methods.
Solution
reference it using ViewChildren
decorator inside board component like this
@ViewChildren(QuareComponent)
squareComp:QueryList<SquareComponent>;
and then inside your method just use it
makeMove(){
console.log(this.squareComp.toArray()) //here are all your square components
}
Answered By - onik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.