I have an angular app where can write, save, edit, and run code snippets.
The angular app looks like this:
var app = angular.module('myApp', ['ui']);
app.value('ui.config', {
codemirror: {
mode: 'text/x-mariadb',
lineNumbers: true,
matchBrackets: true,
theme: 'monokai'
}
});
The view is set up with a simple angularui textarea, with a listing of saved code that you can click on to autofill the textarea.
<textarea ui-codemirror ng-model="code"></textarea>
<a ng-click="fill()">This text will populate the CodeMirror textarea when clicked</a>
And I'd LIKE to use a controller function like this:
angular.module('myApp')
.controller('CodeCtrl', ['$scope', 'Code', function ($scope, Code) {
$scope.fill = function(){
var s = this.innerHTML; //appropriately gets the value from desired anchor tag
$scope.code = setValue(s); //does not set 's' as the value of the CodeMirror instance
}
}
Ideally, I'd be able to use something like editor.setValue
, but given that I set it up using angular-ui, I don't have an editor variable to call on.
EDIT: I have found a somewhat hackish solution
$scope.fill=function(){
var s = this.innerHTML;
var editor = $('.CodeMirror')[0].CodeMirror;
editor.setValue('lorem ipsum yada yada');
}
$scope.code = s;
Does that make any difference? – geedubb Aug 6 '14 at 16:05