如何在codemirror上显示JSON?

问题描述 投票:3回答:1

当前我正在使用ngx-codemirror-代码镜像上的角度包装器。

在我的应用中

显示为HTML

<ngx-codemirror [(ngModel)]="data" [autoFocus]=true [options]="{lineNumbers: true,theme: 'material',mode: 'markdown'}"></ngx-codemirror>

显示为ts

data='';
   json = {
        "title": "Type",
        "description": "A type of product",
        "type": "object"
  };

constructor(){
      this.data = JSON.stringify(this.json);
}

它以一行显示正确的json文本,但我想以json格式显示,而不是一行中的字符串。

我将如何做?

angular codemirror
1个回答
1
投票

您可以在space方法中输入一个空白字符作为JSON.stringify()参数。尝试以下操作

控制器

JSON.stringify()
© www.soinside.com 2019 - 2024. All rights reserved.