Latest Topics...
 |
Two Way Property Binding in Angular Two Way Property Binding in Angular (Select dropdown as example) Child html: <select [(ngModel)]="selection" (change)="changeSelection(selection)"><option value="a">A</option><option value="b">B</option></select> Child ts: import { Component, EventEmitter, Input, Output } from '@angular/core'; @Component({ selector: 'test', templateUrl: './test.component.html' }) export class TestComponent { @Input() selection = ''; @Output() selectionChange: EventEmitter<any> = new EventEmitter<any>(); changeSelection(newSelection: string) { this.selection = newSelection; this.selectionChange.emit(this.selection); } } Parent html: <test [(selection)]="value"></test> Parent ts: value = 'a';
Created By: amos 7/18/2023 9:26:23 AM
|
|
|
|
|
|