Skip to content

Commit 73c3740

Browse files
authored
DEV-1177_Actualizar-ngx-jsonapi-a-Angular-18 (#377)
1 parent 07e0d3b commit 73c3740

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2864
-2578
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
## [2.5.0] - 2025-09-16
10+
11+
- Migrate to angular 18
12+
913
## [2.4.0] - 2025-08-15
1014

1115
- Migrate to angular 17

angular.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"projectType": "application",
1010
"architect": {
1111
"build": {
12-
"builder": "@angular-devkit/build-angular:browser",
12+
"builder": "@angular-devkit/build-angular:browser-esbuild",
1313
"options": {
1414
"outputPath": "demo-dist",
1515
"index": "demo/index.html",

demo/__mocks__/htmlMock.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = '';

demo/app/app.component.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<main>
22
<h1>
33
ngx-jsonapi example
4-
<small class="bg-primary" *ngIf="loading">{{ loading }} <img src="http://s.ytimg.com/yt/img/loader-vflff1Mjj.gif" /></small>
4+
@defer {
5+
<small class="bg-primary">{{ loading }} <img src="http://s.ytimg.com/yt/img/loader-vflff1Mjj.gif" /></small>
6+
}
57
</h1>
68

79
<nav>

demo/app/app.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import { Component } from '@angular/core';
2+
import { CommonModule } from '@angular/common';
3+
import { RouterModule } from '@angular/router';
24
import { JsonapiCore } from 'ngx-jsonapi';
35

46
@Component({
57
selector: 'demo-app',
68
styleUrls: ['./app.component.scss'],
7-
standalone: false,
9+
standalone: true,
10+
imports: [CommonModule, RouterModule],
811
templateUrl: './app.component.html'
912
})
1013
export class AppComponent /* implements OnInit */ {

demo/app/app.module.ts

Lines changed: 0 additions & 60 deletions
This file was deleted.

demo/app/app.routes.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Routes } from '@angular/router';
2+
3+
export const appRoutes: Routes = [
4+
{
5+
path: '',
6+
redirectTo: '/authors',
7+
pathMatch: 'full'
8+
},
9+
{
10+
path: 'authors',
11+
children: [
12+
{ path: '', loadComponent: () => import('./authors/components/authors.component').then((c) => c.AuthorsComponent) },
13+
{ path: ':id', loadComponent: () => import('./authors/components/author.component').then((c) => c.AuthorComponent) }
14+
]
15+
},
16+
{
17+
path: 'systems',
18+
children: [{ path: '', loadComponent: () => import('./systems/systems.component').then((c) => c.SystemsComponent) }]
19+
},
20+
{
21+
path: 'books',
22+
children: [
23+
{ path: '', loadComponent: () => import('./books/components/books.component').then((c) => c.BooksComponent) },
24+
{ path: ':id', loadComponent: () => import('./books/components/book.component').then((c) => c.BookComponent) }
25+
]
26+
}
27+
];

demo/app/authors/authors-routing.module.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

demo/app/authors/authors.module.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

demo/app/authors/components/author.component.html

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<h3>Author #{{ author.id }}, with books and photos</h3>
1+
<h3>Author #{{ author?.id }}, with books and photos</h3>
22
<demo-resource-info [resource]="author"></demo-resource-info>
3-
<!-- <pre>authors.get('{{ author.id }}', {{ '{' }} include: ['books', 'photos'] {{ '}' }});</pre> -->
3+
<!-- <pre>authors.get('{{ author?.id }}', {{ '{' }} include: ['books', 'photos'] {{ '}' }});</pre> -->
44
<ul>
5-
<li>Name: <strong>{{ author.attributes.name }}</strong></li>
6-
<li>Date of birth: <strong>{{ author.attributes.date_of_birth | date }}</strong></li>
7-
<li>Date of dead: <strong>{{ author.attributes.date_of_death | date }}</strong></li>
5+
<li>Name: <strong>{{ author?.attributes.name }}</strong></li>
6+
<li>Date of birth: <strong>{{ author?.attributes.date_of_birth | date }}</strong></li>
7+
<li>Date of dead: <strong>{{ author?.attributes.date_of_death | date }}</strong></li>
88
</ul>
99
<p>
1010
<button (click)="newAuthor()">New author</button>
@@ -13,35 +13,41 @@ <h3>Author #{{ author.id }}, with books and photos</h3>
1313
</p>
1414

1515
<h4>Photos</h4>
16-
<demo-collection-info [collection]="author.relationships.photos"></demo-collection-info>
17-
<span *ngIf="author.relationships.photos.data.length === 0">
18-
This author don't have any photo :(
19-
</span>
20-
<span *ngIf="author.relationships.photos.builded">
21-
<img *ngFor="let photo of author.relationships.photos.data"
22-
[src]="photo.attributes.uri" height="150" style="padding-right: 1em"
23-
title="Book id #{{ photo.id }}"
24-
/>
25-
</span>
16+
<demo-collection-info [collection]="author?.relationships.photos"></demo-collection-info>
17+
@if (author?.relationships.photos.data.length === 0) {
18+
<span>This author don't have any photo :(</span>
19+
}
20+
@if (author?.relationships.photos.builded) {
21+
<span>
22+
<img *ngFor="let photo of author()?.relationships.photos.data"
23+
[src]="photo.attributes.uri" height="150" style="padding-right: 1em"
24+
title="Book id #{{ photo.id }}"
25+
/>
26+
</span>
27+
}
2628

2729
<h4>Books</h4>
28-
<demo-collection-info [collection]="author.relationships.books"></demo-collection-info>
29-
<table class="table table-striped" *ngIf="author.relationships.books.builded">
30-
<thead>
31-
<tr>
32-
<th>ID</th>
33-
<th>Title</th>
34-
<th>Date Published</th>
35-
</tr>
36-
</thead>
37-
<tr *ngFor="let book of author.relationships.books.data">
38-
<td>{{ book.id }}</td>
39-
<td>
40-
<a [routerLink]="['/books', book.id]">{{ book.attributes.title }}</a>
41-
</td>
42-
<td>{{ book.attributes.date_published | date }}</td>
43-
</tr>
44-
</table>
30+
<demo-collection-info [collection]="author?.relationships.books"></demo-collection-info>
31+
@defer {
32+
<table class="table table-striped" *ngIf="author?.relationships.books.builded">
33+
<thead>
34+
<tr>
35+
<th>ID</th>
36+
<th>Title</th>
37+
<th>Date Published</th>
38+
</tr>
39+
</thead>
40+
<ng-container *ngFor="let book of author?.relationships.books.data; trackBy: trackBookId">
41+
<tr>
42+
<td>{{ book.id }}</td>
43+
<td>
44+
<a [routerLink]="['/books', book.id]">{{ book.attributes.title }}</a>
45+
</td>
46+
<td>{{ book.attributes.date_published | date }}</td>
47+
</tr>
48+
</ng-container>
49+
</table>
50+
}
4551

4652
<p>
4753
<a routerLink="/authors">Volver</a>

0 commit comments

Comments
 (0)