-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(angular): update the existing files + add the new angular (renai…
…ssance) practices
- Loading branch information
lgarcia
committed
Jul 20, 2024
1 parent
e5aa6e5
commit 2e5426f
Showing
71 changed files
with
1,056 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
content/1-reactivity/1-declare-state/angular-renaissance/name.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Component, signal } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-name", | ||
template: `<h1>Hello {{ name() }}</h1>`, | ||
}) | ||
export class NameComponent { | ||
name = signal("John"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
content/1-reactivity/2-update-state/angular-renaissance/name.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Component, signal } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-name", | ||
template: `<h1>Hello {{ name() }}</h1>`, | ||
}) | ||
export class NameComponent { | ||
name = signal("John"); | ||
|
||
constructor() { | ||
this.name.set("Jane"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
content/1-reactivity/3-computed-state/angular-renaissance/doublecount.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Component, computed, signal } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-doublecount", | ||
template: `<div>{{ doubleCount() }}</div>`, | ||
}) | ||
export class DoublecountComponent { | ||
count = signal(10); | ||
|
||
doubleCount = computed(() => this.count() * 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
content/2-templating/1-minimal-template/angular-renaissance/helloworld.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Component } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-helloworld", | ||
template: `<h1>Hello world</h1>`, | ||
}) | ||
export class HelloworldComponent {} |
8 changes: 7 additions & 1 deletion
8
content/2-templating/1-minimal-template/angular/helloworld.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import { Component } from "@angular/core"; | ||
import { Component, NgModule } from "@angular/core"; | ||
|
||
@Component({ | ||
selector: "app-helloworld", | ||
template: `<h1>Hello world</h1>`, | ||
}) | ||
export class HelloworldComponent {} | ||
|
||
@NgModule({ | ||
declarations: [HelloworldComponent], | ||
exports: [HelloworldComponent], | ||
}) | ||
export class HelloworldModule {} |
16 changes: 16 additions & 0 deletions
16
content/2-templating/2-styling/angular-renaissance/cssstyle.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Component } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-cssstyle", | ||
template: ` | ||
<h1 class="title">I am red</h1> | ||
<button style="font-size: 10rem">I am a button</button> | ||
`, | ||
styles: ` | ||
.title { | ||
color: red; | ||
} | ||
`, | ||
}) | ||
export class CssStyleComponent {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
content/2-templating/3-loop/angular-renaissance/colors.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Component } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-colors", | ||
template: ` | ||
<ul> | ||
@for (color of colors; track color) { | ||
<li>{{ color }}</li> | ||
} | ||
</ul> | ||
`, | ||
}) | ||
export class ColorsComponent { | ||
colors = ["red", "green", "blue"]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
content/2-templating/4-event-click/angular-renaissance/counter.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Component, signal } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-counter", | ||
template: ` | ||
<p>Counter: {{ count() }}</p> | ||
<button (click)="incrementCount()">+1</button> | ||
`, | ||
}) | ||
export class CounterComponent { | ||
count = signal(0); | ||
|
||
incrementCount() { | ||
this.count.update((count) => count + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
content/2-templating/5-dom-ref/angular-renaissance/inputfocused.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Component, ElementRef, OnInit, viewChild } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-inputfocused", | ||
template: `<input type="text" #inputRef />`, | ||
}) | ||
export class InputfocusedComponent implements OnInit { | ||
inputRef = viewChild.required<ElementRef<HTMLInputElement>>("inputRef"); | ||
|
||
ngOnInit() { | ||
this.inputRef().nativeElement.focus(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
content/2-templating/6-conditional/angular-renaissance/trafficlight.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Component, computed, signal } from "@angular/core"; | ||
|
||
const TRAFFIC_LIGHTS = ["red", "orange", "green"]; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-trafficlight", | ||
template: ` | ||
<button (click)="nextLight()">Next light</button> | ||
<p>Light is: {{ light() }}</p> | ||
<p> | ||
You must | ||
@switch (light()) { | ||
@case ("red") { | ||
<span>STOP</span> | ||
} | ||
@case ("orange") { | ||
<span>SLOW DOWN</span> | ||
} | ||
@case ("green") { | ||
<span>GO</span> | ||
} | ||
} | ||
</p> | ||
`, | ||
}) | ||
export class TrafficlightComponent { | ||
lightIndex = signal(0); | ||
|
||
light = computed(() => TRAFFIC_LIGHTS[this.lightIndex()]); | ||
|
||
nextLight() { | ||
this.lightIndex.update((index) => (index + 1) % TRAFFIC_LIGHTS.length); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
content/3-lifecycle/1-on-mount/angular-renaissance/pagetitle.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
|
||
@Component({ | ||
standalone: true, | ||
selector: "app-pagetitle", | ||
template: `<p>Page title: {{ pageTitle }}</p>`, | ||
}) | ||
export class PagetitleComponent implements OnInit { | ||
pageTitle = ""; | ||
|
||
ngOnInit() { | ||
this.pageTitle = document.title; | ||
} | ||
} |
Oops, something went wrong.