I wish to add a context menu to the scene for each mesh

I have an angular project wherein the three representation is using threeJs. I wish to add a context menu on right-click to the scene. This is what I have so far.

window.addEventListener('mousedown', (e: MouseEvent) => { this.rightClickContextMenu(e); }, false);
        if (document.addEventListener) {
            document.addEventListener('contextmenu', function (e) {
                e.preventDefault();
            }, false);
        } else {
            (<any>document).attachEvent('oncontextmenu', function () {
                window.event.returnValue = false;
            });
        }

public rightClickContextMenu(e: MouseEvent): void {
        var rightclick;
        if (!event) var event = window.event;
        if ((<any>event).which) rightclick = ((<any>event).which == 3);
        else if ((<any>event).button) rightclick = ((<any>event).button == 2);
        if (!rightclick) return;


        const x = e.clientX - this.rect.left;
        const y = e.clientY - this.rect.top;
        var intersect;
        let scenePointer = new th.Vector2();
        scenePointer.x = (x / this.canvas.clientWidth) * 2 - 1;
        scenePointer.y = (y / this.canvas.clientHeight) * - 2 + 1;

        // Determine the component in-focus using raycasting
        this.raycaster.setFromCamera(scenePointer, this.camera);

        var intersects = this.raycaster.intersectObjects(this.scene.children);
        if (intersects.length) {
            intersect = intersects[0].object;
            menu.style.left = x + "px";
            menu.style.top = y + "px";
            menu.style.display = "";
        }
        else {
            intersect = undefined;
        }
    }

So far, on left-click, the color of the mesh changes but nothing happens on right click. I was wondering how do I add on a context menu to the same on right click. Modifications to my code to highlight the correct one would be much appreciated from you guys. I apologise, I am very new to threejs in case this question sounds trivial.

where you specified right click event in this function?

I have had it edited. I am getting an error called: Cannot find the name menu. You can have a look right now :slight_smile:

your code is messy it is not readable, where you initialize context menu? and show proper error with image