Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Last active October 7, 2022 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/9849dff90a27f2495a1ae7b8260dda8f to your computer and use it in GitHub Desktop.
Save NetanelBasal/9849dff90a27f2495a1ae7b8260dda8f to your computer and use it in GitHub Desktop.
@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