This repository was archived by the owner on May 25, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -61,16 +61,6 @@ angular.module('ui.codemirror', [])
6161 if ( angular . isDefined ( scope . $eval ( iAttrs . uiCodemirror ) ) ) {
6262 scope . $watch ( iAttrs . uiCodemirror , updateOptions , true ) ;
6363 }
64- // Specialize change event
65- codeMirror . on ( 'change' , function ( instance ) {
66- var newValue = instance . getValue ( ) ;
67- if ( ngModel && newValue !== ngModel . $viewValue ) {
68- ngModel . $setViewValue ( newValue ) ;
69- }
70- if ( ! scope . $$phase ) {
71- scope . $apply ( ) ;
72- }
73- } ) ;
7464
7565
7666 if ( ngModel ) {
@@ -95,6 +85,18 @@ angular.module('ui.codemirror', [])
9585 var safeViewValue = ngModel . $viewValue || '' ;
9686 codeMirror . setValue ( safeViewValue ) ;
9787 } ;
88+
89+
90+ // Keep the ngModel in sync with changes from CodeMirror
91+ codeMirror . on ( 'change' , function ( instance ) {
92+ var newValue = instance . getValue ( ) ;
93+ if ( newValue !== ngModel . $viewValue ) {
94+ // Changes to the model from a callback need to be wrapped in $apply or angular will not notice them
95+ scope . $apply ( function ( ) {
96+ ngModel . $setViewValue ( newValue ) ;
97+ } ) ;
98+ }
99+ } ) ;
98100 }
99101
100102
You can’t perform that action at this time.
0 commit comments