Skip to content

Commit

Permalink
Merge pull request #1292 from baealex/master
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Nov 27, 2023
2 parents 1ec8c2d + a9804fb commit bd405bb
Show file tree
Hide file tree
Showing 2 changed files with 538 additions and 0 deletions.
316 changes: 316 additions & 0 deletions JinoBae/2023-11-17-angular-standalone-component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
// https://blex.me/@baealex/angular-standalone-component

## NgModule

---

์˜ค๋Š˜๋‚ ์˜ ํ”„๋ก ํŠธ์—”๋“œ ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ์ปดํฌ๋„ŒํŠธ ๊ฐ„์˜ ๊ฒฐํ•ฉ์œผ๋กœ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•˜๋Š”๋ฐ ์•ต๊ทค๋Ÿฌ๋Š” ๊ทธ ์œ„์— ๋ชจ๋“ˆ(NgModule)์ด๋ผ๋Š” ๊ฒƒ์ด ํ•˜๋‚˜ ๋” ์žˆ๋‹ค. ์ด๋Š” ๋Œ€๊ทœ๋ชจ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•  ๋•Œ, ์ฝ”๋“œ์˜ ์žฌ์‚ฌ์šฉ์„ฑ์„ ๋†’ํ˜€์ฃผ๊ณ  ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ตฌ์กฐ๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜ํ•˜๋Š”๋ฐ ๋„์›€๋˜์ง€๋งŒ...

ํŠน์ • ์‚ฌ๋ก€์—์„œ๋Š” ์ฝ”๋“œ์˜ ๋ณต์žก์„ฑ๊ณผ ์˜ค๋ฒ„ํ—ค๋“œ ๋†’ํžˆ๋Š” ์š”์†Œ๊ฐ€ ๋˜๊ธฐ๋„ ํ•œ๋‹ค. ๋ชจ๋“ˆ์€ ์žฌ์‚ฌ์šฉ๋˜๊ธฐ ์ข‹์€ ๋‹จ์œ„์ด์ง€๋งŒ ๋ชจ๋“ˆ์˜ ๊ฐ ์š”์†Œ๋“ค์€ ์žฌ์‚ฌ์šฉ์ด ์–ด๋ ต๋‹ค. ๋ชจ๋“ˆ ๋‚ด์—์„œ ๊ฐ•ํ•˜๊ฒŒ ์˜์กดํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

<br>

#### ๋ชจ๋“ˆ์˜ ํ”ํ•œ ๋ฌธ์ œ ์‚ฌ๋ก€

1. ๋ณต์žก์„ฑ์„ ๋†’ํžŒ ์‚ฌ๋ก€ : ๋ฆฌํŽ™ํ† ๋ง์ด ํ•„์š”ํ•˜๋‹ค. `A` ๋ชจ๋“ˆ์˜ `x` ์ปดํฌ๋„ŒํŠธ๋ฅผ `B` ๋ชจ๋“ˆ๋กœ ์˜ฎ๊ธฐ์ž.
2. ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๋†’ํžŒ ์‚ฌ๋ก€ : ์ด ์ปดํฌ๋„ŒํŠธ๋Š”... ์–ด๋””๋ณด์ž... `SharedModule`์— ๋„ฃ์ž!

๋จผ์ € 1๋ฒˆ ์‚ฌ๋ก€๋ฅผ ์‚ดํŽด๋ณด๋ฉด, ๋ฆฌ์•กํŠธ์—์„œ๋Š” ์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ๋งŒ ๋ด๋„ ์˜์กด์„ฑ์„ ๋Œ€์ฒด๋กœ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ ๋ฐ˜ํ•ด ๋ชจ๋“ˆ ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ์•ต๊ทค๋Ÿฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์ปดํฌ๋„ŒํŠธ ํŒŒ์ผ๋งŒ ๋ณด๊ณ ๋Š” ์ปดํฌ๋„ŒํŠธ์˜ ์˜์กด์„ฑ์„ ์ •ํ™•ํžˆ ํŒŒ์•…ํ•˜๊ธฐ ์–ด๋ ต๋‹ค. ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์†ํ•œ ๋ชจ๋“ˆ์˜ `declarations`์„ ๋น„๋กฏํ•ด ๋ชจ๋“ˆ์ด `imports`ํ•˜๊ณ  ์žˆ๋Š” ๋‹ค๋ฅธ ๋ชจ๋“ˆ์˜ `exports` ๊ตฌ๋ฌธ๋„ ๋ชจ๋‘ ์‚ดํŽด๋ด์•ผ ์˜์กด ๊ด€๊ณ„๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋”ฐ๋ผ์„œ 1๋ฒˆ ์‚ฌ๋ก€์ธ `A` ๋ชจ๋“ˆ์˜ `x` ์ปดํฌ๋„ŒํŠธ๋ฅผ `B` ๋ชจ๋“ˆ๋กœ ์˜ฎ๊ธฐ๋Š” ์ž‘์—…์€ ์˜์กด ๊ด€๊ณ„๋ฅผ ๋ชจ๋‘ ํŒŒ์•…ํ•˜์—ฌ B ๋ชจ๋“ˆ์—๋„ ์˜์กดํ•˜๋Š” ์š”์†Œ๋ฅผ ๋™์ผํ•˜๊ฒŒ ํฌํ•จ์‹œ์ผœ์•ผ ํ•˜๋ฏ€๋กœ ๋ฆฌํŒฉํ† ๋ง์„ ์–ด๋ ต๊ฒŒ ๋งŒ๋“ค๊ณ  ๊ฒฐ๊ณผ์ ์œผ๋กœ ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋น„๋กฏํ•ด ๊ฐ ์š”์†Œ๋“ค์˜ ์žฌ์‚ฌ์šฉ์„ฑ์„ ๋–จ์–ดํŠธ๋ฆฐ๋‹ค.

2๋ฒˆ ์‚ฌ๋ก€๋Š” ์ถฉ๋ถ„ํžˆ ๋…๋ฆฝ ๊ฐ€๋Šฅํ•œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๊ฑฐ๋Œ€ํ•œ ๋ชจ๋“ˆ์— ํฌํ•จ๋˜์–ด (์•ต๊ทค๋Ÿฌ๋Š” ๋ชจ๋“ˆ๊ฐ„์— ๊ฒฐํ•ฉ์ด ์ด๋ค„์ง€๋ฏ€๋กœ) ํ•˜๋‚˜์˜ ์ปดํฌ๋„ŒํŠธ๋งŒ ํ˜ธ์ถœ์ด ํ•„์š”ํ•œ ์ƒํ™ฉ์—์„œ ๋ฌถ์—ฌ์žˆ๋Š” ๋ชจ๋“  ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๊ฐ™์ด ํ˜ธ์ถœ๋˜์–ด ๋ถˆํ•„์š”ํ•œ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.

<br>

#### SCAM!

์ด๊ฒƒ์— ๋Œ€ํ•œ ํ•ด๊ฒฐ์ฑ…์œผ๋กœ ์ œ์•ˆ๋œ ๊ฒƒ์ด \*SCAM ํŒจํ„ด์ด๋‹ค.

> \*SCAM = Single Component Angular Module
ํ•˜๋‚˜์˜ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ํ•˜๋‚˜์˜ ๋ชจ๋“ˆ์— ์†ํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ปดํฌ๋„ŒํŠธ, ํŒŒ์ดํ”„, ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ์ž‘์€ ๋‹จ์œ„์˜ ๋ชจ๋“ˆ๋กœ ๋งŒ๋“ ๋‹ค. ๊ทธ๋Ÿฌ๋ฉด ๋ณด๋‹ค ์‰ฝ๊ฒŒ ์˜์กด ๊ด€๊ณ„๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ณ  ์žฌ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๋ฉฐ, ์•ต๊ทค๋Ÿฌ์—์„œ๋Š” ๋ชจ๋“ˆ ๋‹จ์œ„๋กœ ์ง€์—ฐ ๋กœ๋”ฉ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ถˆํ•„์š”ํ•œ ์˜ค๋ฒ„ํ—ค๋“œ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค์ง€ ์•Š์„ ์ˆ˜ ์žˆ๋‹ค.

์•ต๊ทค๋Ÿฌ์˜ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ์ด ํŒจํ„ด์˜ ์—ฐ์žฅ์„ ์ด๋‹ค. ์•ต๊ทค๋Ÿฌ 14 ๋ถ€ํ„ฐ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋ผ๋Š” ๊ฐœ๋…์„ ์‹คํ—˜์ ์œผ๋กœ ๋„์ž…ํ•˜์—ฌ ์ปดํฌ๋„ŒํŠธ, ํŒŒ์ดํ”„, ๋””๋ ‰ํ‹ฐ๋ธŒ๋ฅผ ๋ชจ๋“ˆ์—†์ด ๋…๋ฆฝํ˜•์œผ๋กœ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•˜์˜€๊ณ , ์ด๋Š” ์ปดํฌ๋„ŒํŠธ ๊ฐ„์˜ ๊ฒฐํ•ฉ์œผ๋กœ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋งŒ๋“ค์—ˆ๋‹ค.

๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ๋ชจ๋“ˆ์— ๋Œ€ํ•œ ์ดํ•ด ์—†์ด๋„ ์•ต๊ทค๋Ÿฌ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ์–ด ์ง„์ž… ์žฅ๋ฒฝ์„ ๋‚ฎ์ถฐ์ค€๋‹ค๊ณ  ํ•˜๋Š”๋ฐ... ์ตœ๊ทผ ์•ต๊ทค๋Ÿฌ๋ฅผ ์ ‘ํ•œ ์ž…๋ฌธ์ž๋กœ์จ ๋ชจ๋“ˆ๊ณผ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์„ž์—ฌ์žˆ๋Š” ํ˜„์žฌ ๊ตฌ์กฐ์—์„œ ๋” ๋งŽ์€ ์–ด๋ ค์›€๊ณผ ํ˜ผ๋ž€์„ ๊ฒช์€ ๋“ฏ ํ•˜๋‹ค. (๋‚˜์ค‘์—๋Š” ์ •๋ง ์‰ฌ์›Œ์งˆ์ง€๋„?)

์—ฌํ•˜์ง€๊ฐ„ ๋ชจ๋“ˆ์— ๋Œ€ํ•ด์„œ ์–ด๋Š์ •๋„ ์ดํ•ดํ•˜๋‹ˆ ์ด์ œ์•ผ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๊ฐ€ ๋ˆˆ์— ๋“ค์–ด์˜ค๊ธฐ ์‹œ์ž‘ํ–ˆ๋‹ค. ์‹ค์ œ๋กœ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ ๋งŒ์œผ๋กœ ์ž‘์€ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋งŒ๋“ค์–ด๋ณด๋‹ˆ ๋ณ„๋‹ค๋ฅธ ๋ฌธ์ œ๊ฐ€ ์—†์—ˆ์œผ๋ฉฐ ๋ชจ๋“ˆ์„ ์ž‘์„ฑํ•˜์ง€ ์•Š์œผ๋‹ˆ ์˜คํžˆ๋ ค ๊ฐ„๊ฒฐํ•˜๊ฒŒ ๋Š๊ปด์ง€๊ธฐ๋„ ํ–ˆ๋‹ค.

<grid-image col="1">
![](https://static.blex.me/images/content/2023/11/17/2023111720_aO72TlqIQVTTP6LSiEKm.png)
<caption>์ถœ์ฒ˜ : reddit - r/angular</caption>
</grid-image>

์ปค๋ฎค๋‹ˆํ‹ฐ ๋ฐ˜์‘์„ ์‚ดํŽด๋ณด๋‹ˆ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์œ„ํ•ด์„œ ๋ชจ๋“ˆ์„ ์œ ์ง€ํ•˜๊ฒ ๋‹ค๋Š” ์˜๊ฒฌ๋„ ์žˆ๊ณ , ๋ณ€ํ™”๋ฅผ ๊ธ์ •์ ์œผ๋กœ ์ƒ๊ฐํ•˜๋Š” ์‚ฌ์šฉ์ž๋„ ๋งŽ๋‹ค. ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ์•ต๊ทค๋Ÿฌ 16 ๋ถ€ํ„ฐ๋Š” ์‹คํ—˜ ๊ธฐ๋Šฅ์ด ์•„๋‹Œ ์ •์‹ ๊ธฐ๋Šฅ์œผ๋กœ ๋„์ž…๋˜์—ˆ๋‹ค.

<br>

## ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ

---

> ์—ฌ๊ธฐ์„œ๋Š” ํฌ๊ด„์ ์ธ ์šฉ์–ด๋กœ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋ผ๋Š” ๋‹จ์–ด๋ฅผ ์‚ฌ์šฉํ•˜์ง€๋งŒ ํŒŒ์ดํ”„๋‚˜ ๋””๋ ‰ํ‹ฐ๋ธŒ๋„ ๋…๋ฆฝํ˜•์œผ๋กœ ์„ ์–ธํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ ํฌํ•จ๋œ๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋„ ์ข‹๋‹ค.
๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋ฅผ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๊ณ , ๊ธฐ์กด ๋ชจ๋“ˆ๊ณผ ๊ณต์กด์‹œํ‚ค๋Š”์ง€, ๊ธฐ์กด ์•ฑ ๋ชจ๋“ˆ์„ ๊ฑท์–ด๋‚ด๊ณ  ์‹œ์ž‘๋ถ€ํ„ฐ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋กœ ์ „ํ™˜ํ•  ์ˆ˜ ์žˆ์„์ง€, ๋ผ์šฐํ„ฐ์—์„œ ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ ˆ์ด์ง€ ๋กœ๋”ฉํ•˜๋Š” ๋ฐฉ์•ˆ์— ๋Œ€ํ•ด์„œ ์‚ดํŽด๋ณธ๋‹ค.

<br>

#### standalone

๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ƒ์„ฑํ•  ๋•Œ `@Component` ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ ์•ˆ์— `standalone` ์˜ต์…˜์„ ์„ค์ •ํ•ด์ฃผ๋ฉด ๋œ๋‹ค. ๊ทธ๋Ÿผ ์ปดํฌ๋„ŒํŠธ ๋‚ด๋ถ€์—์„œ๋„ `imports`๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

```ts
@Component({
standalone: true, // +
selector: 'app-my-component',
imports: [
// ...
],
template: `
<p>My Component</p>
`,
styles: [
]
})
```

<br>

#### ๋ชจ๋“ˆ๊ณผ ๊ณต์กดํ•˜๊ธฐ

ํ›—๋‚  ์•ต๊ทค๋Ÿฌ์—์„œ ๋ชจ๋“ˆ์ด ์‚ฌ๋ผ์ง„๋‹ค๋ฉด ๋ง์€ ๋‹ฌ๋ผ์ง€๊ฒ ์ง€๋งŒ, ์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ธฐ ์œ„ํ•ด ํ˜„์žฌ๋กœ์จ๋Š” ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ์ปดํฌ๋„ŒํŠธ๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ๋‘”๊ฐ‘ํ•œ ๋ชจ๋“ˆ(SCAM)์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋Š”๊ฒŒ ํŽธํ•˜๋‹ค.

###### ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ <- ๋ชจ๋“ˆ

`imports` ๊ตฌ๋ฌธ์—๋Š” ๋ชจ๋“ˆ๋งŒ ์„ ์–ธํ•  ์ˆ˜ ์žˆ๋‹ค. ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋„ ์ž‘์€ ๋‹จ์œ„์˜ ๋ชจ๋“ˆ์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜์ž. ๋”ฐ๋ผ์„œ ์ผ๋ฐ˜ ์ปดํฌ๋„ŒํŠธ์˜ ๊ฒฝ์šฐ์—๋Š” `imports` ๊ตฌ๋ฌธ์— ์ง์ ‘ ๋ช…์‹œํ•  ์ˆ˜ ์—†์œผ๋ฏ€๋กœ ๊ธฐ์กด๊ณผ ๋™์ผํ•˜๊ฒŒ ๋ชจ๋“ˆ์„ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ค๊ฑฐ๋‚˜ ๋˜๋Š” `standalone`์„ ๋ช…์‹œํ•˜์—ฌ ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋กœ ์ „ํ™˜ํ•˜์—ฌ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋‹ค.

**์ž˜๋ชป๋œ ์œ ํ˜•**

```ts
// general.component.ts
@Component({
selector: 'app-general',
template: `
...
`,
styles: [
]
})
export class GeneralComponent {

}

// standalone.componet.ts
@Component({
standalone: true,
selector: 'app-standalone',
imports: [
CommonModule,
GeneralComponent // error
],
template: `
<app-general />
`,
styles: [
]
})
export class StandaloneComponent {

}
```

**์ˆ˜์ • ๋ฐฉ์•ˆ 1 : Module์„ ํ†ตํ•œ ๊ฒฐํ•ฉ**

```ts
// general.module.ts
@NgModule({
declarations: [
GeneralComponent,
],
imports: [
CommonModule
],
exports: [
GeneralComponent,
]
})
export class GeneralModule { }

// standalone.componet.ts
@Component({
standalone: true,
selector: 'app-standalone',
imports: [
CommonModule,
GeneralModule
],
template: `
<app-general />
`,
styles: [
]
})
export class StandaloneComponent {

}
```

**์ˆ˜์ • ๋ฐฉ์•ˆ 2 : ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋กœ ์ „ํ™˜**

```ts
// general.component.ts
@Component({
standalone: true,
selector: 'app-general',
imports: [
CommonModule,
],
template: `
...
`,
styles: [
]
})
export class GeneralComponent {

}

// standalone.componet.ts
@Component({
standalone: true,
selector: 'app-standalone',
imports: [
CommonModule,
GeneralComponent
],
template: `
<app-general />
`,
styles: [
]
})
export class StandaloneComponent {

}
```

<br>

###### ๋ชจ๋“ˆ <- ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ

๋ชจ๋“ˆ์—์„œ ์ผ๋ฐ˜ ์ปดํฌ๋„ŒํŠธ๋Š” `declarations`์— ์„ ์–ธ๋จ์— ๋ฐ˜ํ•ด ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” `imports` ๊ตฌ๋ฌธ์— ์„ ์–ธ๋˜์–ด์•ผ ํ•จ์„ ์œ ์˜ํ•ด์•ผ ํ•œ๋‹ค.

```ts
// app.module.ts
@NgModule({
declarations: [
AppComponent,
// StandaloneComponent (x)
],
imports: [
BrowserModule,
AppRoutingModule,
StandaloneComponent // (o)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

// app.component.ts
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
template: `
<app-standalone />
`,
styles: []
})
export class AppComponent {
title = 'app';
}
```

<br>

#### ๋ถ€ํŠธ์ŠคํŠธ๋žฉ

๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ์•ต๊ทค๋Ÿฌ์˜ ์ง„์ž…์ ์œผ๋กœ ์ง€์ •ํ•˜์—ฌ ๋ชจ๋“ˆ์„ ์ „ํ˜€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ ๋„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ๋‹ค. ์ฐจ์ด์ ์„ ์‚ดํŽด๋ณด๊ธฐ ์œ„ํ•ด์„œ ๋ชจ๋“ˆ์ด ์ง„์ž…์ ์œผ๋กœ ์ง€์ •๋˜๋Š” ๊ธฐ์กด์˜ ํ˜•ํƒœ๋ฅผ ์‚ดํŽด๋ณด์ž.

```ts
// main.ts
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));

// app.module.ts
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
],
providers: [
// ...
],
bootstrap: [AppComponent]
})
export class AppModule { }
```

๊ธฐ์กด ๋ชจ๋“ˆ์˜ ๊ฒฝ์šฐ ๋ผ์šฐํŒ… ๋ชจ๋“ˆ์„ ์•ฑ ๋ชจ๋“ˆ ๋‚ด์—์„œ ์ž„ํฌํŠธํ•˜์—ฌ ๋ถ€ํŠธ์ŠคํŠธ๋žฉํ•˜๋Š” ๊ตฌ์กฐ์ด์ง€๋งŒ, ๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋Š” ๋ผ์šฐํŒ… ๋ชจ๋“ˆ์ด๋ผ๋Š” ๊ฐœ๋… ์—†์ด๋„ `provideRouter`๋ฅผ ํ™œ์šฉํ•ด ๋ผ์šฐํ„ฐ๋ฅผ ์ ์šฉ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋‹ค.

```ts
// main.ts
bootstrapApplication(AppComponent, {
providers: [
provideRouter(routes),
// ...
]
}).catch((err) => console.error(err));

// app.component.ts
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule, RouterOutlet],
template: `
...
`,
styles: [],
})
export class AppComponent {
title = 'app';
}
```

<br>

#### ๋ ˆ์ด์ง€ ๋กœ๋”ฉ

๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋ผ์šฐํ„ฐ์—์„œ ์†์‰ฝ๊ฒŒ ๋ ˆ์ด์ง€ ๋กœ๋”ฉ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

```ts
const routes: Routes = [{
path: '',
loadComponent: () => import('./list/list.component').then(m => m.ListComponent),
}]
```

๋…๋ฆฝํ˜• ์ปดํฌ๋„ŒํŠธ๋ฅผ ํ™œ์šฉํ•˜๋ฉด ์•ต๊ทค๋Ÿฌ๋กœ ์ž‘์€ ๊ทœ๋ชจ์˜ ์•ฑ์„ ๋งŒ๋“ค๋•Œ ๋น„๊ต์  ์œ ์šฉํ•  ๋“ฏ ํ•˜๋‹ค.

<br>

## ์ฐธ๊ณ ์ž๋ฃŒ

---

- Your Angular Module is a SCAM! ยท Medium @Younes
[#](https://medium.com/marmicode/your-angular-module-is-a-scam-b4136ca3917b)
- Getting started with standalone components ยท Angular
[#](https://angular.io/guide/standalone-components)
- Ngmodules vs Standalone Components or Angular2 vs Angular3 ยท DEV @layzee
[#](https://blog.stackademic.com/ngmodules-vs-standalone-components-or-angular2-vs-angular3-ba54fab04ce3)
Loading

0 comments on commit bd405bb

Please sign in to comment.