-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add standalone component & two-way binding to ng input example (#205)
- Loading branch information
Showing
4 changed files
with
22 additions
and
23 deletions.
There are no files selected for viewing
11 changes: 6 additions & 5 deletions
11
content/6-form-input/1-input-text/angular/input-hello.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,13 +1,14 @@ | ||
import { Component } from "@angular/core"; | ||
import { CommonModule } from '@angular/common'; | ||
import {FormsModule} from "@angular/forms"; | ||
|
||
@Component({ | ||
selector: "app-input-hello", | ||
template: `<input [value]="text" (change)="handleInputChange($event)" />`, | ||
standalone: true, | ||
imports: [CommonModule, FormsModule], | ||
template: `<p>{{text}}</p> | ||
<input [(ngModel)]="text">`, | ||
}) | ||
export class InputHelloComponent { | ||
text = ""; | ||
|
||
handleInputChange(event: Event) { | ||
this.text = (event.target as HTMLInputElement).value; | ||
} | ||
} |
10 changes: 5 additions & 5 deletions
10
content/6-form-input/2-checkbox/angular/is-available.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,21 +1,21 @@ | ||
import { Component } from "@angular/core"; | ||
import { CommonModule } from '@angular/common'; | ||
import {FormsModule} from "@angular/forms"; | ||
|
||
@Component({ | ||
selector: "app-is-available", | ||
standalone: true, | ||
imports: [CommonModule, FormsModule], | ||
template: ` | ||
<input | ||
id="is-available" | ||
type="checkbox" | ||
[checked]="isAvailable" | ||
(change)="handleChange()" | ||
[(ngModel)] = "isAvailable" | ||
/> | ||
<label for="is-available">Is available</label> | ||
`, | ||
}) | ||
export class IsAvailableComponent { | ||
isAvailable = false; | ||
|
||
handleChange() { | ||
this.isAvailable = !this.isAvailable; | ||
} | ||
} |
14 changes: 6 additions & 8 deletions
14
content/6-form-input/3-radio/angular/pick-pill.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,33 +1,31 @@ | ||
import { Component } from "@angular/core"; | ||
import { CommonModule } from '@angular/common'; | ||
import {FormsModule} from "@angular/forms"; | ||
|
||
@Component({ | ||
selector: "app-pick-pill", | ||
standalone: true, | ||
imports: [CommonModule, FormsModule], | ||
template: ` | ||
<div>Picked: {{ picked }}</div> | ||
<input | ||
id="blue-pill" | ||
[checked]="picked === 'blue'" | ||
type="radio" | ||
value="blue" | ||
(change)="handleChange($event)" | ||
[(ngModel)]="picked" | ||
/> | ||
<label for="blue-pill">Blue pill</label> | ||
<input | ||
id="red-pill" | ||
[checked]="picked === 'red'" | ||
type="radio" | ||
value="red" | ||
(change)="handleChange($event)" | ||
[(ngModel)]="picked" | ||
/> | ||
<label for="red-pill">Red pill</label> | ||
`, | ||
}) | ||
export class PickPillComponent { | ||
picked = "red"; | ||
|
||
handleChange(event) { | ||
this.picked = event.target.value; | ||
} | ||
} |
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