diff --git a/README.md b/README.md index 94b860b..0327497 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,16 @@ The ng-model will be watched for to set the Ace EditSession value (by [setValue] _The ui-ace directive stores and expects the model value to be a standard javascript String._ +### Can be read only + +Simple demo +```html +
+or +Check me to make Ace readonly:
+
+``` + ### Ace instance direct access For more interaction with the Ace instance in the directive, we provide a direct access to it. diff --git a/test/ace.spec.js b/test/ace.spec.js index 8e7efa1..02895cf 100644 --- a/test/ace.spec.js +++ b/test/ace.spec.js @@ -86,13 +86,25 @@ describe('uiAce', function () { describe('readOnly', function () { it('should read only option true', function () { - $compile('
')(scope); - expect(_ace).toBeDefined(); + $compile('
')(scope); + scope.$apply(); + expect(_ace.getReadOnly()).toBeTruthy(); + $compile('
')(scope); + scope.$apply("foo = true"); expect(_ace.getReadOnly()).toBeTruthy(); }); it('should read only option false', function () { $compile('
')(scope); - expect(_ace).toBeDefined(); + scope.$apply(); + expect(_ace.getReadOnly()).toBeFalsy(); + $compile('
')(scope); + scope.$apply(); + expect(_ace.getReadOnly()).toBeFalsy(); + $compile('
')(scope); + expect(_ace.getReadOnly()).toBeFalsy(); + scope.$apply("foo = true"); + expect(_ace.getReadOnly()).toBeTruthy(); + scope.$apply("foo = false"); expect(_ace.getReadOnly()).toBeFalsy(); }); }); diff --git a/ui-ace.js b/ui-ace.js index fefd22b..157f5ba 100644 --- a/ui-ace.js +++ b/ui-ace.js @@ -72,9 +72,9 @@ angular.module('ui.ace', []) session.setMode("ace/mode/" + opts.mode); } - if (angular.isDefined(opts.readOnly)) { - acee.setReadOnly(opts.readOnly); - } + attrs.$observe('readonly', function (value) { + acee.setReadOnly(value === 'true'); + }); // Value Blind if (angular.isDefined(ngModel)) {