Once I select an item from the Category dropdown list and hit save button, I am getting an error msg as follows:
The JSON value could not be converted to System.Collections.Generic.List`1[System.Guid]. Path: $.categories | LineNumber: 0 | BytePositionInLine: 377
enter image description here
I want to select just single item from the category dropdown list. It looks like there is an issue when I assign value from the selected list.
enter image description here
categories: this.selectedCategories ?? []
my edit-tentry.component.html looks like this
<ng-container *ngIf="categories$ | async as categories">
<select class="form-control" [(ngModel)]="selectedCategories" name="categories">
<option *ngFor="let category of categories;" [value]="category.id">{{category.name}}
</option>
</select>
</ng-container>
my edit-tentry.component.ts looks like
export class EditTentryComponent implements OnInit, OnDestroy {
id: string | null = null;
model?: Tentry
categories$?: Observable<Category[]>;
selectedCategories?: string[];
ngOnInit(): void {
this.categories$ = this.categoryService.getAllCategories();
this.routeSubscription = this.route.paramMap.subscribe({
next: (params) => {
this.id = params.get('id');
//Get Tentry from API
if(this.id){
this.getTentrySubscription = this.tentryService.getTentryById(this.id).subscribe({
next: (response) => {
this.model = response;
this.selectedCategories = response.categories.map(x => x.id);
}
});
}
console.log("Get Selected Categories On InIt: ", this.selectedCategories);
}
});
}
onFormSubmit(): void{
if(this.model && this.id)
{
var updateTentry: UpdateTentry = {
//......
//......
ticketStatus: this.model.ticketStatus,
categories: this.selectedCategories ?? []
};
this.updateTentrySubscription = this.tentryService.updateTentry(this.id, updateTentry)
.subscribe({
next:(response) => {
this.router.navigateByUrl('/admin/tentry')
}
});
}
}
export interface Category {
id: string;
name: string;
urlHandle: string;
}
Vith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.