diff --git a/src/ui-ace.js b/src/ui-ace.js index a664fb1..bba1699 100644 --- a/src/ui-ace.js +++ b/src/ui-ace.js @@ -272,6 +272,10 @@ angular.module('ui.ace', []) ngModel.$render = function () { session.setValue(ngModel.$viewValue); }; + + acee.on('change', function (event) { + ngModel.$setViewValue(acee.getValue()); + }); } // Listen for option updates diff --git a/test/ace.spec.js b/test/ace.spec.js index a6f9ec7..d71d1af 100644 --- a/test/ace.spec.js +++ b/test/ace.spec.js @@ -284,6 +284,24 @@ describe('uiAce', function () { // expect(scope.foo).toBe('baz'); }); + + it('should update the model if text inserted programmatically', function () { + $compile('
')(scope); + scope.$apply('foo = "bar"'); + + _ace.insert('baz '); + + expect(scope.foo).toBe('baz bar'); + }); + + it('should update the model if text removed programmatically', function () { + $compile('
')(scope); + scope.$apply('foo = "baz bar"'); + + _ace.removeWordRight(); + + expect(scope.foo).toBe(' bar'); + }); }); describe('when the model is undefined/null', function () {