Angular PrimeNG Autocomplete how to pass ID value of object

  angular, primefaces, primeng

I seem to need some help here. Hopefully this makes sense.
I am trying to use PrimeNG autocomplete with multiple selection array.

I am filtering through object category name for the user to select but I want to pass the incidentCategoryId of the json object and I am struggling to do that.

How do I get the incidentCategoryId to be passed in the JSON form object…

Other PrimeNG options allow you to bind the value to the template

JSON Objects

[
{
    "categoryName": "Hardware",        
    "incidentCategoryId": 1
},
{
    "categoryName": "Software",      
    "incidentCategoryId": 2
},
{
    "categoryName": "Network",
    "incidentCategoryId": 3
}]

.ts

 filterCategory(event) {
  let filtered : any[] = [];
  let query = event.query;
  for(let i = 0; i < this.incidentcategoryService.categoryArray.length; i++) {
      let category = this.incidentcategoryService.categoryArray[i];
      if (category.categoryName.toLowerCase().indexOf(query.toLowerCase()) == 0) {
        filtered.push(category.categoryCombinedString)
    }       
  }
  this.filteredCategories = filtered;
  console.log(this.filteredCategories)

}

HTML

<p-autoComplete [(ngModel)]="categories"[suggestions]="filteredCategories" name="incidentCategoryId" (completeMethod)="filterCategory($event)" [multiple]="true">
      </p-autoComplete>

FORM VALUE JSON

{
 "otherStuff": "hey I'm other stuff part of the form object being passed"
 "incidentCategory": [ "Hardware", "Software" ]
}

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.