I am using NGX-Chips in Angular. I am saving the typed in chips into Firebase and retrieving them.
Problem is, when it tries to render the saved chips, it can't and throws an error.
Before posting this question, I tried to read through and follow this issue on GitHub and added the displayBy
and identifyBy
tag with no avail.
THE ERROR
Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed
HTML Code
<tag-input
(onAdd)="onCategoryAdded($event, product.external_id)"
[displayBy]="'display'"
[identifyBy]="'$key'"
[(ngModel)]="product.categories"
[ngModelOptions]="{standalone: true}"
theme="minimal"
placeholder="Categories"
>
<tag-input-dropdown [autocompleteItems]="categories"></tag-input-dropdown></tag-input>
</tag-input>
In my controller, I set an observable item, listen for value changes and assign those to mentioned observable.
public products: Observable<any[]>;
ngOnInit() {
this.products = this.afd.list('/products').valueChanges();
}
onCategoryAdded(event, product) {
this.afd.database.ref('/products').orderByChild('external_id').equalTo(product).once('value', (snapshot) => {
snapshot.forEach((product) => {
this.afd.database.ref('/products').child(product.key).child('categories').push({
'display' : event.display,
'value' : event.value
});
});
});
}
product.categories
prints out like below when I add {{product.categories | json}}
to my html.
{ "-LfN8VhSrWBye-8ukSAq": { "display": "Featured", "value": "Featured" } }
Should I alter how I save the categories in Firebase so it returns a different value or should I transform the returned value somehow within the controller?