Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

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');
}
share|improve this question
    
In the example for ui-codemirror they use e.g. $scope.code = s; Does that make any difference? – geedubb Aug 6 '14 at 16:05
    
Nope, still nothing. Nothing interesting in the javascript console, either – johncorser Aug 6 '14 at 17:14
    
I think it's because I'm using angular modules. See my edit. – johncorser Aug 6 '14 at 17:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.