Building a CodeMirror component


I’m trying to build my first component and having a little problem. I’m using the codemirror.js library to incorporate a code editor into my site and I have the code editor displaying on the screen, but I can’t figure out how to get my data to show up in the control.

I want the data from content to display in the editor when it first loads and I’d like to have the data bind to that property.

Here is a jsbin if anyone can help:


Updated at

There’s a couple of things to notice,

tagName: "textarea",

this tells the component to render as a textarea so you don’t need the template.


this is how you get a reference to the component’s element (instead of document.findByElementId).{

this is necessary because the codemirror component doesn’t know anything about ember’s run loop. This will make sure that the change is integrated into ember’s lifecycle.


this watches for changes to the component’s ‘value’ and updates the codemirror component.


Thanks for the description of the changes. That does help but it still doesn’t seem to populate the codemirror component with the data when the page jsfiddle loads. Anything else that I could be missing?


This is the approach I took in a project I’ve been working on.

It’s used like this

{{code-area initialCode=lesson_code endResult=endResult}}

There’s a few more examples of different versions in that repo as well as some unit tests.

Hope this helps.


Hi, I updated the fiddle to set the initial value.

I’m not sure why it wasn’t working before, the codemirror instance seems to ignore the value passed into it’s config when initialized…