I see in primeng components the use something like ngModel (two-way data binding) style for some property like this
[(selection)]="selectedItem";
it 's look like
@Input() selection;
@Output() selection:EventEmitter<any> = new EventEmitter<any>();
how I can implement something like this and is it possible to do for more than single property like
<component-a [(selection)]="selectedItem" [(data)]="selectedData"></component-a>
https://angular.io/guide/template-syntax#two-way-binding
This means, you only need a corresponding
selectionChange
method on your child component. Hence, if you want the banana-in-a-box binding for your propertyselection
ofParentComponent
intoChildComponent
, follow these steps:Include the following in your
ChildComponent
:In your
ParentComponent
template:In summary, if your property name is
x
, you only need to name its corresponding EventEmitter toxChange
and do the banana-in-a-box syntax for the child component[(x)] = "parentProperty"
and Angular takes care of the rest.In your child component (component-a) you need an
@output
and then you notify parent component about a changed value by
See also Angular2: https://stackoverflow.com/a/33220997/3710630
In your child component you have to implement two-way binding interface like this:
It's mandatory to name
@Output
filed by addingpropertyNameChange
to@Input
name. So you can use it in your parent component temlate like this:Angular docs
To create two-way binding for property
selection
use:And to change selection in component as shown below: