Code Mirrorディレクティブを使用して、テキスト領域をコードとしてフォーマットしています。
何が機能していますか:
<textarea ui-codemirror type="textarea" ng-model="x"></textarea>
オプションを次のように設定できます
<textarea ui-codemirror="editorOptions" type="textarea" ng-model="x"></textarea>
そしてコントローラーで:
$scope.editorOptions = {
name: 'javascript',
json: true,
smartIndent: false,
tabSize: 2,
lineWrapping : true,
lineNumbers: true,
mode: 'javascript'
}
機能していないもの:
モデルの別の部分に基づいて editorOptions を動的に変更しようとしています (Javascript と Markdown をサポートしています)。
だから私はこれを試しています:
$scope.editorOptions = {
json: {
name: 'javascript',
json: true,
smartIndent: false,
tabSize: 2,
lineWrapping : true,
lineNumbers: true,
mode: 'javascript'
},
markdown: {
name: 'markdown',
json: false,
smartIndent: false,
tabSize: 2,
lineWrapping : true,
lineNumbers: true,
mode: 'markdown'
}
};
そして、これをHTMLで:
<select ng-model='editorType' required ng-options='option.value as option.name for option in editorTypes'></select>
<textarea ui-codemirror="editorOptions[editorType]" type="textarea" ng-model="x"></textarea>
私の質問は、選択モデル (editorType) の値を使用して、コード ミラー ディレクティブで使用されているオプション オブジェクトを指定するにはどうすればよいですか?
私はもう試した
<textarea ui-codemirror="editorOptions.[editorType]" type="textarea" ng-model="x"></textarea>
<textarea ui-codemirror="editorOptions[$scope.editorType]" type="textarea" ng-model="x"></textarea>
すべて役に立たない。
これを行う適切な方法を知っている人はいますか?
大変感謝します!
更新 これは正しい構文だと思います:
ui-codemirror="editorOptions[editorType]".
変数が変更されたことを認識しないディレクティブに問題があると思います。