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

Commit 0f5802e

Browse files
committed
fix: not watching ui-codemirror-opts attribute
Following #56
1 parent 36dfbc5 commit 0f5802e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/ui-codemirror.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ angular.module('ui.codemirror', [])
3838
}, opts);
3939
}
4040

41-
if (iAttrs.uiCodemirror) {
41+
if (iAttrs.uiCodemirror || iAttrs.uiCodemirrorOpts) {
4242
var codemirrorDefaultsKeys = Object.keys(window.CodeMirror.defaults);
43-
scope.$watch(iAttrs.uiCodemirror, function updateOptions(newValues, oldValue) {
43+
scope.$watch(iAttrs.uiCodemirror || iAttrs.uiCodemirrorOpts, function updateOptions(newValues, oldValue) {
4444
codemirrorDefaultsKeys.forEach(function (key) {
4545
if (newValues.hasOwnProperty(key) && newValues[key] !== oldValue[key]) {
4646
codeMirror.setOption(key, newValues[key]);

test/codemirror.spec.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('uiCodemirror', function () {
303303
});
304304

305305

306-
it('should watch the options', function () {
306+
it('should watch the options (attribute directive)', function () {
307307

308308
scope.cmOption = { readOnly: true };
309309
$compile('<div ui-codemirror="cmOption"></div>')(scope);
@@ -316,6 +316,19 @@ describe('uiCodemirror', function () {
316316
expect(codemirror.getOption('readOnly')).toBeFalsy();
317317
});
318318

319+
it('should watch the options (element directive)', function () {
320+
321+
scope.cmOption = { readOnly: true };
322+
$compile('<ui-codemirror ui-codemirror-opts="cmOption"></div>')(scope);
323+
scope.$digest();
324+
325+
expect(codemirror.getOption('readOnly')).toBeTruthy();
326+
327+
scope.cmOption.readOnly = false;
328+
scope.$digest();
329+
expect(codemirror.getOption('readOnly')).toBeFalsy();
330+
});
331+
319332
it('should watch the options (object property)', function () {
320333

321334
scope.cm = {};

0 commit comments

Comments
 (0)