目前我正在使用ngx-codemirror -一个角包装在codemirror上。
在我的应用里
html作为显示
<ngx-codemirror [(ngModel)]="data" [autoFocus]=true [options]="{lineNumbers: true,theme: 'material',mode: 'markdown'}"></ngx-codemirror>T作为表演
data='';
json = {
"title": "Type",
"description": "A type of product",
"type": "object"
};
constructor(){
this.data = JSON.stringify(this.json);
}它在一行中正确地显示了json文本,但是我想用json格式而不是单行中的字符串来显示它。
我该怎么做?
发布于 2020-06-04 08:29:50
可以在space方法中作为JSON.stringify()参数发送空空格字符。尝试以下几点
控制器
data = '';
json = {
"title": "Type",
"description": "A type of product",
"type": "object"
};
ngOnInit() {
this.data = JSON.stringify(this.json, null, ' '); // <-- string literal ' ' as `space` argument
}还可以通过发送数字来修改缩进空间。就像。JSON.stringify(this.json, null, 4)表示4个空格的缩进。
模板
<ngx-codemirror #codemirror
[options]="codeMirrorOptions"
[(ngModel)]="data"
(ngModelChange)="setEditorContent($event)">
</ngx-codemirror>工作示例:斯塔克布利茨
https://stackoverflow.com/questions/62189788
复制相似问题