ngModel.$render()
loops-and-spells opened this issue · 4 comments
need
ngModel.$render()
after
ngModel.$setViewValue newValue
or model may not update values.
This doesn't quite sound right. Can you provide an example of the model not updating correctly?
I will send from the office, I had to store the cursor position and call
render or the data would not match up. It was a restangularized model so
maybe something else is going on.
On Jun 22, 2014 10:03 PM, "Jeremy" notifications@github.com wrote:
This doesn't quite sound right. Can you provide an example of the model
not updating correctly?—
Reply to this email directly or view it on GitHub
#58 (comment)
.
here are the changes i needed for the ngModel.$render override, calling $render would reset the cursor position.
ngModel.$render = ->
safeViewValue = ngModel.$viewValue or ""
cursor_pos = codeMirror.getCursor()
codeMirror.setValue ngModel.$viewValue
codeMirror.setCursor(cursor_pos)
and here where the ngModel is synced from CodeMirror
scope.$apply ->
ngModel.$setViewValue newValue
ngModel.$render()
the issue I was having was when I submitted the model to a restful route, it was returning as an empty string.
Page is a restangular resource, and the model passed to the CodeMirror directive.
$scope.page = Page
$scope.onSavePage = () ->
Page.put()
Thanks! I'll look into this in detail this weekend. For the record, what versions of angular and codemirror are you using?