I'm working on Metronic Theme's Angular 6 project. It has below code. Can you tell me what is the functionality of [(action)]="action"
. I know how to bind to input metadata (i.e. @Input()
). We normally do like so
<m-login *ngIf="action === 'login'" [action]="action"></m-login>
But here it is different. It is like 2-way model binding. But we normally use this syntax for that [(ngModel)]="model"
. Any clue?
auth.component.html
<m-login *ngIf="action === 'login'" [(action)]="action"></m-login>
login.ts
export class LoginComponent implements OnInit, OnDestroy {
@Output() actionChange = new Subject<string>();
@Input() action: string;
}
if your property name is
action
, you only need to name its correspondingEventEmitter
toactionChange
and do the banana-in-a-box syntax for the child component[(action)] = "parentProperty"
and Angular takes care of the rest.