jQuery-contextMenu icon indicating copy to clipboard operation
jQuery-contextMenu copied to clipboard

Issue running jquery-contextMenu with Angular

Open mrizescu opened this issue 7 years ago • 9 comments

I am getting an error trying to use jquery-contextMenu (v2.7.0) with Angular 6. It was installed with npm install --save jquery-contextmenu. In pure Javascript same code is working fine, within Angular I get the following error in Chrome. Any advice would be appreciated. Thanks

core.js:14576 ERROR TypeError: node.contextMenu is not a function at HTMLDocument. (app.component.ts:595) at mightThrow (jquery.js:3534) at process (jquery.js:3602) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:16126) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188) at push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask (zone.js:496) at ZoneTask.invoke (zone.js:485) at timer (zone.js:2054)

The code is very simple, something like this: $(function(){ let channelContainer = '#channel'; let node : any = $(channelContainer); node.contextMenu({ selector: 'div', items: { "item1": { name: "Delete", callback: function() { ... } }, "sep1": "---------", "cancel": { name: "Cancel", callback: function() { } } } }); });

mrizescu avatar Nov 28 '18 21:11 mrizescu

Could you try and initialize this menu with the following call?

$.contextMenu({
  selector: '#channel div',
  items: {
    "item1": {
      name: "Delete",
      callback: function () {      
      }
    },
    "sep1": "---------",
    "cancel": {
      name: "Cancel",
      callback: function () {
      }
    }
  }
});

bbrala avatar Nov 29 '18 10:11 bbrala

Thanks for the quick response. When I try that initialization I get a compilation error error TS2339: Property 'contextMenu' does not exist on type 'JQueryStatic'

mrizescu avatar Nov 29 '18 15:11 mrizescu

Perhaps you should include the TypeScript definition.

https://www.npmjs.com/package/@types/jquery.contextmenu

bbrala avatar Nov 30 '18 08:11 bbrala

I installed that (npm install --save @types/jquery.contextmenu) and I get the same compilation error as before: error TS2339: Property 'contextMenu' does not exist on type 'JQueryStatic'. Do I need an import in the TypeScript file for the contextMenu definition?

mrizescu avatar Nov 30 '18 16:11 mrizescu

If you have any further recommendation regarding the Typescript definition please let me know. Thanks!

mrizescu avatar Dec 04 '18 14:12 mrizescu

Hmm, that is pretty weird since the definition does add contextMenu to JQueryStatic as you can see here (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/jquery.contextmenu/index.d.ts)

Unfortunately i don't use typescript :(

bbrala avatar Jan 16 '19 15:01 bbrala

I use // @ts-ignore.

I also both import $ from "jquery" and use expose-loader.

patarapolw avatar Apr 15 '19 02:04 patarapolw

@patarapolw could you give example please?

pers1307 avatar Apr 18 '19 11:04 pers1307

Someone managed to solve?

fernandomaraujo avatar Dec 28 '21 15:12 fernandomaraujo