I am simply trying to bind data from a dropdown menu with ngModel. There is an error I receive when the app loads that makes some sense.
browser_adapter.js:84 EXCEPTION: No value accessor for ''
This leads me to believe that the error is stemming from the fact that ngModel is not initially bound with any data when the app loads.
I'm not the best at using Observables... so beware.
Partial of the html dropdown
<p-dropdown [options]="actionsToTake" (onChange)="onToggleCreateActionInput()"
[(ngModel)]="action"></p-dropdown>
Relevant TypeScript (excluded imports)
export class ActionView {
public actionsToTake: SelectItem[] = [];
public action: Action = new Action();
constructor (private actionCreateService: ActionCreateService) {
// populate dropdown list (actionsToTake) with data from service call
this.actionCreateService.getActionFields().subscribe((resp) => {
for (let i = 0; i < resp.data.data.actionElm.length; i++) {
this.actionsToTake.push({label: resp.data.data.actionElm[i].name,
value: resp.data.data.actionElm[i].name});
}
});
}
public onToggleCreateActionInput = (action): void => {
// test if something in "action" exists, and then do something based on that
};
}
So, when the app initially loads, action is empty. I would expect that an empty value bound to ngModel wouldn't break the app, but maybe I am misinterpreting the error. Ultimately I want the selected item to be bound, and I think getting past this error will get me to that point.