Reputation: 3498
Which function should execute when form is submitted is dependent on whether it is edit mode or not. Is it possible to do something like this in Angular (the code below just throws an error):
<form novalidate (ngSubmit)="{editMode ? saveUser() : addUser()}" [formGroup]="userForm">
Upvotes: 0
Views: 44
Reputation: 86740
You can do like this -
Just remove {}
sign from the event call like this -
<form novalidate (ngSubmit)="editMode ? saveUser() : addUser()" [formGroup]="userForm">
Upvotes: 2
Reputation: 519
try this
<form novalidate (ngSubmit)="editMode ? saveUser() : addUser()" [formGroup]="userForm">
Upvotes: 1
Reputation: 1
No, you can't. But what you can do is:
<form novalidate (ngSubmit)="saveUser(editMode ? 'add' : 'save')"[formGroup]="userForm">
saveUser(mode: 'add' | 'save') {
switch(mode) { .... }
}
Upvotes: 0