ค้นหาเว็บไซต์

javascript - ดู Children บน canvas


ฉันมีคำถามเล็กน้อยเกี่ยวกับ viewchildren ฉันสับสนเล็กน้อย ดังนั้นฉันสามารถใช้ viewchild ได้ แต่ view children ใช้งานไม่ได้

ดังนั้นโดยพื้นฐานแล้ว viewchild กับ 1 แคนวาส:

ใน HTML:

<canvas #mycan style="background:white; border: 1px solid black;" class='center'></canvas>

ใน TS:

@ViewChild("mycan") myCanvas;
...
let canvas = this.myCanvas.nativeElement;
this.context = canvas.getContext("2d");

อย่างไรก็ตาม สำหรับเด็กน้อยบางคน ฉันรู้สึกค่อนข้างสับสน:

<ion-slide *ngFor="let card of cardList">
    <canvas #mycan style="background:white; border: 1px solid black;" class='center'></canvas>
</ion-slide>

และใน TS ของฉัน:

@ViewChildren('mycan') canvas: QueryList<HTMLCanvasElement>;
...
for(var index in this.canvas){
let canvas = this.canvas[index].nativeElement;
var context = canvas.getContext("2d");

ปัญหาคือแคนวาสเป็นค่า null

ฉันก็ลองโดยการเปลี่ยน HTMLCanvasElement เป็น ElementRef แล้ว แต่ก็ไม่ทำงาน :(

คุณอาจจะมีไอเดียไหม?

ขอบคุณมากๆ!!! :)

ด้วยความนับถือ

เจฟฟรีย์ มุเซลลี