Skip to content

Commit 0aa1625

Browse files
committed
feat: implement custom two-way binding for rectangle size in rect component
1 parent 61cc7c5 commit 0aa1625

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

06-cmp-deep-dive/custom-2w-binding-starting-project/src/app/app.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@
88
<input type="number" step="1.0" [(ngModel)]="rectSize.height" />
99
</p>
1010
</div>
11-
<app-rect />
11+
<app-rect [(size)]="rectSize"/>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div
22
id="rect"
3-
[style.width]="'200px'"
4-
[style.height]="'100px'"
3+
[style.width]="size.width + 'px'"
4+
[style.height]="size.height + 'px'"
55
(click)="onReset()"
66
></div>
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component } from '@angular/core';
1+
import { Component, EventEmitter, Input, Output } from '@angular/core';
22

33
@Component({
44
selector: 'app-rect',
@@ -8,9 +8,11 @@ import { Component } from '@angular/core';
88
styleUrl: './rect.component.css',
99
})
1010
export class RectComponent {
11-
// Todo: Implement custom two-way binding
11+
12+
@Input({required: true}) size!: { width: string, height: string };
13+
@Output() sizeChange = new EventEmitter<{ width: string, height: string }>();
1214

1315
onReset() {
14-
// ...
16+
this.sizeChange.emit({ width: '200', height: '100' });
1517
}
1618
}

0 commit comments

Comments
 (0)