更改 ui-codemirror 中的选项

Changing option in ui-codemirror

我正在尝试使用 ui-codemirror,并且有以下代码:JSBin:

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="https://codemirror.net/lib/codemirror.css">
  <script src="https://code.jquery.com/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <script src="https://codemirror.net/lib/codemirror.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-codemirror/0.3.0/ui-codemirror.js"></script>
</head>
<body ng-app="YourApp"> 
  <div ng-controller="YourController">
    <div ng-model='testCM3' ui-codemirror='{{option}}'></div>
    {{option}}<br/>
    <a href="#" ng-click="changeOption()">changeOption</a>
  </div>
  <script type="text/javascript">     
    angular.module('YourApp', ['ui.codemirror'])
    .controller('YourController', ['$scope', function ($scope) {
      $scope.option = "{ lineNumbers: true }"
      $scope.testCM3 = "testCM3";
      $scope.changeOption = function () {
        if ($scope.option === "{ lineNumbers: true }") $scope.option = "{ lineNumbers: false }"
        else $scope.option = "{ lineNumbers: true }"
      }
    }])
  </script> 
</body>
</html>

通过单击 changeOption,我希望行号为 hidden/shown。我们可以看到 option 的值发生了变化,但是 codemirror 没有变化。有谁知道我的代码有什么问题吗?

我找到了:

  1. ui-codemirror='{{option}}'应该写成ui-codemirror='option'
  2. option 应该定义为对象而不是字符串

JSBin