yabab-dev/ng2-codemirror

Change the theme or other configuration?

Dracks opened this issue · 6 comments

Hello,

I'm trying to change the theme or other configuration after create it (with buttons) but changing the object config, don't change anything on the component, I was looking, and there is nothing to notify codemirror to change it. How can i do that?

Thanks

Did you import the proper themes or modes for example in your component?

The themes are working fine, the problem was, if you start the codemirror with a theme, and after that you wish to change it, like the example of themes: http://codemirror.net/demo/theme.html There is no option, because if you change config, it doesn't change the running instance config, codemirror have a method to hot change a property of the config ( $codemirror.setOption() )

To the OP: You can change the codemirror configuration by accessing the underlying codemirror object which is being wrapped by ng2-codemirror. Eg:

import { ViewChild }        from '@angular/core';
import { CodemirrorComponent }      from 'ng2-codemirror';

And then inside the class body:

@ViewChild(CodemirrorComponent)
private codemirrorComponent: CodemirrorComponent;

onChange(event: any) {
    this.codemirrorComponent.instance.setOption('mode', 'javascript');
}

Actually I've put an @output parameter to extract the instance of codeMirror, (I copied my code) I don't know the @ViewChild decorator when I did that. Thanks!

@Dracks Is that a valid workaround then? Did it work?

Sorry @sharath1608 I leave the company some month ago, and I forget reply you (I was on hollidays when you reply)

I think the @ViewChild should work :) My changes worked.

Sorry for the late response