Last active
October 7, 2022 13:05
-
-
Save NetanelBasal/9849dff90a27f2495a1ae7b8260dda8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
template: ` | |
<form #f="ngForm"> | |
<ng-container ngModelGroup="assignee"> | |
<div> | |
<input | |
type="radio" | |
name="$case" | |
[ngModel]="assigneeCase" | |
value="userId" | |
/> | |
User | |
<input | |
type="radio" | |
name="$case" | |
[ngModel]="assigneeCase" | |
value="userGroupId" | |
/> | |
User Group | |
</div> | |
<div [ngSwitch]="f.value.assignee?.$case"> | |
<ng-container *ngSwitchCase="'userId'"> | |
<select name="userId" ngModel required> | |
<option ngValue="userA">User A</option> | |
<option ngValue="userB">User B</option> | |
</select> | |
</ng-container> | |
<ng-container *ngSwitchCase="'userGroupId'"> | |
<select name="userGroupId" ngModel required> | |
<option ngValue="groupA">Group A</option> | |
<option ngValue="groupB">Group B</option> | |
</select> | |
</ng-container> | |
</div> | |
</ng-container> | |
<button>Submit</button> | |
</form> | |
`, | |
}) | |
export class TaskFormComponent { | |
form: Task = { | |
name: '', | |
assignee: { | |
$case: 'userId', | |
userId: '', | |
}, | |
}; | |
get assigneeCase() { | |
return this.form.assignee.$case; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment