-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv13-.ts
More file actions
39 lines (32 loc) · 1.08 KB
/
v13-.ts
File metadata and controls
39 lines (32 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Component, EventEmitter, Input, NgModule, Output } from "@angular/core";
import { CommonModule } from "@angular/common";
import { BehaviorSubject, map } from "rxjs";
@Component({
selector: "my-component",
template: `
<ng-container *ngIf="myDoubledValue$ | async as doubled">
<ng-container *ngIf="doubled === 10; else notMagic">
<h2>Congrats!</h2>
<p>That's the magic number!</p>
</ng-container>
<ng-template #notMagic>
<p *ngIf="doubled > 10">Too high...</p>
<p *ngIf="doubled < 10">Too low...</p>
</ng-template>
</ng-container>
`,
})
export class MyComponent {
myValue$ = new BehaviorSubject(0);
myDoubledValue$ = this.myValue$.pipe(map((val) => val * 2));
@Input() set myValue(value: number) {
this.myValue$.next(value);
}
@Output() myOutput = new EventEmitter<number>();
}
@NgModule({
declarations: [MyComponent],
imports: [CommonModule],
exports: [MyComponent],
})
export class MyComponentModule {}