0

I'm using Angular 5 and typescript and included the code editor codemirror into my page.

I want to overwrite a nested functionality: Codemirror.hint.function

In javascript it looks like:

Codemirror.hint.function = function(param) = {
...
}

How can I do this in typescript? Because it is nested, I can't define a simple interface.

I want to define an own autocompletion for this editor.

solved it: Codemirror specific solution: Code: stackblitz

1 Answer 1

1

You can use this

Object.defineProperty(Codemirror.hint, 'function', {value: () => {/* your override */}});

Although I highly doubt that an object can have a function function, since it is a javascript keyword.

EDIT I don't know why or how, but the typescript definition in your blitz didn't declare CodeMirror as a global variable. Probably minification, but I won't search further.

So I added the script with a CDN in index.html, and now it works.

Here is the stackblitz.

Sign up to request clarification or add additional context in comments.

12 Comments

Cannot find Codemirror. Should I define an interface ?
How do you access it in your Typescript component ?
At the moment i have no possibility to access it. Thats why I'm stuck.
declare var Codemirror: any; ?
Please post your code, I'm getting really tired of people saying they do something, while they don't, and then complain about the solution not working because they didn't do it just because they didn't like the answer. Or even better, create a stackblitz with your issue.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.