I get a list of categories from my service, and i want to bind the category of my controller with the option selected in my select, what i tried:
<select class="form-control" id="category" [(ngModel)]="category">
<option *ngFor="let category of categoryservice.getCategories()">
{{category.name}}
</option>
</select>
My controller:
category : Category = new Category(0, '', '', 0);
constructor(private categoryservice : CategoryService) { }
ngOnInit() {
}
With this code i get the error: If ngModel is used within a form tag, either the name attribute must be set or the form control must be defined as 'standalone' in ngModelOptions.
But i'm not using ngModel within a form, so i don't know what could be the problem.
Thanks!