-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support
outputFromObservable
and input.required
- Loading branch information
Anh Pham
committed
Apr 20, 2024
1 parent
8fef3e5
commit 095cc97
Showing
2 changed files
with
17 additions
and
22 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
17 changes: 12 additions & 5 deletions
17
examples/example-app-v17/src/app/dashboard/dashboard-hero.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,28 @@ | ||
import { UpperCasePipe } from '@angular/common'; | ||
import { Component, EventEmitter, Input, Output } from '@angular/core'; | ||
import { Component, input, output } from '@angular/core'; | ||
import { outputFromObservable, outputToObservable } from '@angular/core/rxjs-interop'; | ||
import { Subject } from 'rxjs'; | ||
|
||
import { Hero } from '../model/hero'; | ||
|
||
@Component({ | ||
selector: 'dashboard-hero', | ||
template: ` <div (click)="click()" class="hero"> | ||
{{ hero.name | uppercase }} | ||
{{ hero().name | uppercase }} | ||
</div>`, | ||
styleUrls: ['./dashboard-hero.component.css'], | ||
standalone: true, | ||
imports: [UpperCasePipe], | ||
}) | ||
export class DashboardHeroComponent { | ||
@Input() hero!: Hero; | ||
@Output() selected = new EventEmitter<Hero>(); | ||
hero = input.required<Hero>(); | ||
selected = output<Hero>(); | ||
selected$ = new Subject<Hero>(); | ||
selectedFromObservable = outputFromObservable(this.selected$); | ||
selectedToObservable$ = outputToObservable(this.selected); | ||
|
||
click() { | ||
this.selected.emit(this.hero); | ||
this.selected$.next(this.hero()); | ||
this.selected.emit(this.hero()); | ||
} | ||
} |