Skip to content
This repository has been archived by the owner on May 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #54 from whitehat101/on-change-apply
Browse files Browse the repository at this point in the history
scope.$apply and $digest already in use
  • Loading branch information
douglasduteil committed Apr 29, 2014
2 parents 18317b7 + 1d46946 commit 5cdb98f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/ui-codemirror.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ angular.module('ui.codemirror', [])
if (angular.isDefined(scope.$eval(iAttrs.uiCodemirror))) {
scope.$watch(iAttrs.uiCodemirror, updateOptions, true);
}
// Specialize change event
codeMirror.on('change', function (instance) {
var newValue = instance.getValue();
if (ngModel && newValue !== ngModel.$viewValue) {
ngModel.$setViewValue(newValue);
}
if (!scope.$$phase) {
scope.$apply();
}
});


if (ngModel) {
Expand All @@ -95,6 +85,18 @@ angular.module('ui.codemirror', [])
var safeViewValue = ngModel.$viewValue || '';
codeMirror.setValue(safeViewValue);
};


// Keep the ngModel in sync with changes from CodeMirror
codeMirror.on('change', function (instance) {
var newValue = instance.getValue();
if (newValue !== ngModel.$viewValue) {
// Changes to the model from a callback need to be wrapped in $apply or angular will not notice them
scope.$apply(function() {
ngModel.$setViewValue(newValue);
});
}
});
}


Expand Down

0 comments on commit 5cdb98f

Please sign in to comment.