vinoth kumar

vinoth kumar

  • NA
  • 37
  • 4k

Property 'getContext' does not exist on type '{ sceneFunc: () => void;

Feb 16 2023 5:56 AM

 Hi All,

When i using canvas in konva by using angular13 to draw a pattern lock.i getting this error how to solve this.

 

private newLine(dots: Konva.Circle[], strokeStyle = "rgba(255,255,255,0.5)") {

    return new Konva.Shape({

      sceneFunc: function () {

        const ctx: any = this.getContext();  //////// this line gets an error

        const dot1 = dots[0];

        ctx.beginPath();

        ctx.moveTo(dot1.x(), dot1.y());

        for (let i = 1; i < dots.length; i += 1) {

          const dot: Konva.Circle = dots[i];

          ctx.lineTo(dot.x(), dot.y());

        }

        ctx.lineJoin = "round";

        ctx.lineCap = "round";

        ctx.strokeStyle = strokeStyle;

        ctx.lineWidth = 2;

        ctx.stroke();

        ctx.closePath();

      }

    });

  }


Answers (3)