Skip to content

Commit e10b850

Browse files
committed
migrate to standalone & remove modules
1 parent 46a119a commit e10b850

39 files changed

+277
-343
lines changed

apps/ng-demo/eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default tsESLint.config(...baseConfig, ...angular, ...storybook, {
1212
},
1313
},
1414
rules: {
15+
'@angular-eslint/prefer-standalone-component': 'off',
1516
'@angular-eslint/prefer-standalone': 'error',
1617

1718
'@typescript-eslint/explicit-module-boundary-types': 'error',
Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { Component } from '@angular/core';
2+
import { HeaderComponent } from '../components/header/header.component';
3+
import { RouterOutlet } from '@angular/router';
24

35
@Component({
4-
selector: 'app-root',
5-
template: `
6+
selector: 'app-root',
7+
8+
template: `
69
<app-header></app-header>
710
<router-outlet></router-outlet>
811
`,
9-
styles: [
10-
`
12+
styles: [
13+
`
1114
:host {
1215
display: block;
1316
max-width: var(--screen-width);
@@ -16,7 +19,7 @@ import { Component } from '@angular/core';
1619
box-sizing: border-box;
1720
}
1821
`,
19-
],
20-
standalone: false
22+
],
23+
imports: [HeaderComponent, RouterOutlet],
2124
})
2225
export class AppComponent {}

apps/ng-demo/src/app/app.module.ts

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

apps/ng-demo/src/app/app.routes.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,25 @@ export const appRoutes: Route[] = [
44
{ path: '', redirectTo: 'home', pathMatch: 'full' },
55
{
66
path: 'home',
7-
loadChildren: () =>
8-
import('../pages/home/home.module').then((m) => m.HomeModule),
7+
loadComponent: () => import('../pages/home/home.component'),
98
},
109
{
1110
path: 'tag/:tag',
1211
pathMatch: 'full',
13-
loadChildren: () =>
14-
import('../pages/home/home.module').then((m) => m.HomeModule),
12+
loadComponent: () => import('../pages/home/home.component'),
1513
},
1614
{
1715
path: 'videos',
18-
loadChildren: () =>
19-
import('../pages/videos/videos.module').then((m) => m.VideosModule),
16+
loadComponent: () => import('../pages/videos/videos.component'),
2017
},
2118
{
2219
path: 'users/:username',
23-
loadChildren: () =>
24-
import('../pages/user-profile/user-profile.module').then(
25-
(m) => m.UserProfileModule
26-
),
20+
loadComponent: () => import('../pages/user-profile/user-profile.component'),
2721
},
2822
{
2923
path: ':user/:slug',
30-
loadChildren: () =>
31-
import('../pages/article-detail/article-detail.module').then(
32-
(m) => m.ArticleDetailModule
33-
),
24+
loadComponent: () =>
25+
import('../pages/article-detail/article-detail.component'),
3426
},
3527
{
3628
path: 'not-found',
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { Component, Input, OnChanges, OnInit } from '@angular/core';
22

3-
import { NgModule } from '@angular/core';
4-
import { CommonModule } from '@angular/common';
5-
import { RouterModule } from '@angular/router';
3+
import { NgIf, NgFor, DatePipe } from '@angular/common';
4+
import { RouterLink } from '@angular/router';
65
import { Article } from '../../models/articles';
76
import { DateagoPipe } from '../../pipes/dateago.pipe';
87

98
@Component({
10-
selector: 'app-article-card',
11-
templateUrl: './article-card.component.html',
12-
styleUrls: ['./article-card.component.scss'],
13-
standalone: false
9+
selector: 'app-article-card',
10+
11+
templateUrl: './article-card.component.html',
12+
styleUrls: ['./article-card.component.scss'],
13+
imports: [RouterLink, NgIf, NgFor, DatePipe, DateagoPipe],
1414
})
1515
export class ArticleCardComponent implements OnChanges {
1616
@Input() article!: Article;
@@ -22,10 +22,3 @@ export class ArticleCardComponent implements OnChanges {
2222
this.article?.organization?.slug || this.article.user.username;
2323
}
2424
}
25-
26-
@NgModule({
27-
declarations: [ArticleCardComponent, DateagoPipe],
28-
imports: [CommonModule, RouterModule.forChild([])],
29-
exports: [ArticleCardComponent],
30-
})
31-
export class ArticleCardModule {}
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
import { CommonModule } from '@angular/common';
2-
import { Component, NgModule } from '@angular/core';
3-
import { RouterModule } from '@angular/router';
1+
import { Component } from '@angular/core';
42

53
@Component({
6-
selector: 'app-header',
7-
templateUrl: './header.component.html',
8-
styleUrls: ['./header.component.scss'],
9-
standalone: false
4+
selector: 'app-header',
5+
6+
templateUrl: './header.component.html',
7+
styleUrls: ['./header.component.scss'],
108
})
119
export class HeaderComponent {
1210
constructor() {}
1311
}
14-
15-
@NgModule({
16-
declarations: [HeaderComponent],
17-
imports: [CommonModule, RouterModule.forChild([])],
18-
exports: [HeaderComponent],
19-
})
20-
export class HeaderModule {}

apps/ng-demo/src/components/scoll-tracker/scroll-tracker.directive.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ import { fromEvent, Subscription } from 'rxjs';
99
import { debounceTime } from 'rxjs/operators';
1010

1111
@Directive({
12-
/* eslint-disable @angular-eslint/directive-selector */
13-
selector: '[scrollTracker]',
14-
standalone: false
12+
/* eslint-disable @angular-eslint/directive-selector */
13+
selector: '[scrollTracker]',
1514
})
1615
export class ScrollTrackerDirective implements OnDestroy, OnInit {
1716
@Output() scrollingFinished = new EventEmitter<void>();

apps/ng-demo/src/main.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
1-
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
1+
import { BrowserModule, bootstrapApplication } from '@angular/platform-browser';
2+
import {
3+
withInterceptorsFromDi,
4+
provideHttpClient,
5+
} from '@angular/common/http';
6+
import { provideRouter } from '@angular/router';
7+
import { appRoutes } from './app/app.routes';
8+
import { AppComponent } from './app/app.component';
9+
import { importProvidersFrom } from '@angular/core';
210

3-
import { AppModule } from './app/app.module';
4-
5-
platformBrowserDynamic()
6-
.bootstrapModule(AppModule)
7-
.catch((err) => console.error(err));
11+
bootstrapApplication(AppComponent, {
12+
providers: [
13+
importProvidersFrom(BrowserModule),
14+
provideHttpClient(withInterceptorsFromDi()),
15+
provideRouter(appRoutes),
16+
],
17+
}).catch((err) => console.error(err));

apps/ng-demo/src/pages/article-detail/article-detail.component.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import { ArticleDetailStore } from './article/services/article-detail.store';
55
import { CommentsStore } from './article/services/comments.store';
66
import { UserStore } from '../../state/user.store';
77
import { UserArticlesStore } from '../../state/user-articles.store';
8+
import { NgIf, AsyncPipe } from '@angular/common';
9+
import { ReactionsComponent } from './article/reactions/reactions.component';
10+
import { ArticleDetailsComponent } from './article/article-details/article-details.component';
11+
import { UserDetailComponent } from './user/user-detail/user-detail.component';
812

913
@Component({
10-
selector: 'app-article-detail',
11-
template: `
14+
selector: 'app-article-detail',
15+
16+
template: `
1217
<aside>
1318
<app-reactions
1419
*ngIf="reaction$ | async as reactions"
@@ -25,8 +30,8 @@ import { UserArticlesStore } from '../../state/user-articles.store';
2530
<app-user-detail *ngIf="user" [user]="user"></app-user-detail>
2631
</ng-container>
2732
`,
28-
styles: [
29-
`
33+
styles: [
34+
`
3035
:host {
3136
display: grid;
3237
grid-gap: 1rem;
@@ -37,11 +42,17 @@ import { UserArticlesStore } from '../../state/user-articles.store';
3742
grid-template-columns: 4rem minmax(0, 7fr) minmax(0, 3fr);
3843
}
3944
`,
40-
],
41-
viewProviders: [ArticleDetailStore, UserStore, CommentsStore],
42-
standalone: false
45+
],
46+
viewProviders: [ArticleDetailStore, UserStore, CommentsStore],
47+
imports: [
48+
NgIf,
49+
ReactionsComponent,
50+
ArticleDetailsComponent,
51+
UserDetailComponent,
52+
AsyncPipe,
53+
],
4354
})
44-
export class ArticleDetailComponent implements OnInit {
55+
export default class ArticleDetailComponent implements OnInit {
4556
article$ = this.articleDetailStore.article$.pipe(
4657
tap((article) => {
4758
if (article?.user) {

apps/ng-demo/src/pages/article-detail/article-detail.module.ts

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

0 commit comments

Comments
 (0)