Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions projects/demo/src/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<h2>ngx-json-treeview</h2>

<h3>Primatives</h3>
<div class="json-container">
<ngx-json-treeview [json]="13" />
<ngx-json-treeview [json]="'hello, world!'" />
<ngx-json-treeview [json]="true" />
<ngx-json-treeview [json]="null" />
</div>

<h3>Collapsed</h3>
<div class="json-container">
<ngx-json-treeview [json]="json" [expanded]="false" />
Expand Down Expand Up @@ -41,3 +33,16 @@ <h3>Clickable Nodes</h3>
</div>
}
</div>

<h3>Primatives</h3>
<div class="json-container">
<ngx-json-treeview [json]="13" />
<ngx-json-treeview [json]="'hello, world!'" />
<ngx-json-treeview [json]="true" />
<ngx-json-treeview [json]="null" />
</div>

<h3>Arrays</h3>
<div class="json-container">
<ngx-json-treeview [json]="[1, 2, 3, 'hello', 'world']" />
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</section>
} @else {
@if (_currentDepth() === 0) {
<span class="puctuation">{{ '{' }}</span>
<span class="puctuation">{{ rootType() === 'array' ? '[' : '{' }}</span>
}
@for (segment of segments(); track segment) {
@for (segment of segments(); track segment; let i = $index) {
<section [class]="'segment segment-type-' + segment.type">
@let expandable = isExpandable(segment);
<section class="segment-main">
Expand All @@ -33,9 +33,12 @@
isClickableValue()(segment)
? onValueClickHandler(segment)
: undefined
">
{{ segment.description }}
</span>
"
>{{ segment.description }}</span
>
<span class="puctuation">{{
i < segments().length - 1 ? ',' : ''
}}</span>
} @else if (expandable && segment.expanded) {
<span class="puctuation">
@if (segment.type === 'array') {
Expand Down Expand Up @@ -71,7 +74,7 @@
</section>
}
@if (_currentDepth() === 0) {
<span class="puctuation">{{ '}' }}</span>
<span class="puctuation">{{ rootType() === 'array' ? ']' : '}' }}</span>
}
}
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,13 @@ export class NgxJsonTreeviewComponent {
*/
_currentDepth = input<number>(0);

rootType = computed<string>(() =>
this.json() != null ? typeof this.json() : 'null'
);
rootType = computed<string>(() => {
if (this.json() === null) {
return 'null';
} else if (Array.isArray(this.json())) {
return 'array';
} else return typeof this.json();
});
segments = computed<Segment[]>(() => {
const json = decycle(this.json());
if (typeof json === 'object' && json != null) {
Expand Down