2

I am trying to do addapt the contenteditable directive I foud on angularjs website (http://docs.angularjs.org/guide/concepts#directives).

My problem is that if I change the value inside the contenteditable div inside my controller, the scope value is updated but the value in the div isn't. I would like to be able to do something like this in my main controller :

$scope.content = $scope.content.concat("added text");

This updated the $scope.content but it does not update the contenteditable div. And so, if I click in the div to edit it, my modification is gone.

In order to make it work, I would have to call ctrl.$render from my controller but I can't find any documentation on what is this 4th parameter of the link function.

Does anyone have an idea what this 'ctrl' parameter represents and if by change some know how to solve my problem :)

4
  • 1
    The 4th parameter is the controller specified in the require parameter. In this case ctrl is an instance of the ngModelController. Commented Mar 20, 2013 at 18:27
  • 1
    The forms page and the NgModelController page have contenteditable examples, but not the directives page. Which page are you looking at? Commented Mar 20, 2013 at 18:30
  • I am using the one I the forms page except I have removed the line "ctrl.$setViewValue(elm.html());" which I have replaced by ctrl.$render(). Commented Mar 20, 2013 at 18:49
  • But I have just tried the directive from the NgModelController page and it works like expected :) Thanks! Commented Mar 20, 2013 at 18:56

1 Answer 1

1

As of this writing (3/20/2013), there are two problems with the Plunker from the forms page:

  1. missing form-example.
    HTML should be: <html ng-app="form-example2">
  2. contentEditable should be contenteditable.
    HTML should be: <div contenteditable ng-model="content">Some content</div>

Plunker with link to append to $scope.content in the controller.

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

Comments

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.