Elo wszystkim mam formatkę w której mam input o nazwie category i chcę zmienić ten input na listę rozwijaną pobieraną z mojego api.
tak wygląda input
<div class="form-group">
<label for="category">Category</label>
<input
type="text"
class="form-control"
id="category"
required
[(ngModel)]="job.category"
name="category"
/>
</div>
a tak sam to przerobiłem i nie działa
<div class="form-group">
<label for="category">Category</label>
<select>
<option *ngFor="let category of myCategories" [ngValue]="category"
type="text"
class="form-control"
id="category"
required [(ngModel)]="job.category"
name="category">
{{ category }}
</option>
</select>
</div>
dodaje component ts
@Component({
selector: 'app-add-jobs',
templateUrl: './add-jobs.component.html',
styleUrls: ['./add-jobs.component.css']
})
export class AddJobsComponent implements OnInit {
myCategories = this.retrieveCategories();
job = {
title: '',
category: '',
endDated: '',
email: '',
published: false
};
submitted = false;
constructor(private jobService: JobService, private categoryService: CategoryService) {
}
ngOnInit(): void {
this.retrieveCategories();
}
saveJob() {
const data = {
title: this.job.title,
category: this.job.category,
company: this.job.company,
city: this.job.city,
description: this.job.description,
endDated: this.job.endDated,
email: this.job.email
};
this.jobService.create(data)
.subscribe(
response => {
console.log(response);
this.submitted = true;
},
error => {
console.log(error);
});
}
retrieveCategories() {
this.categoryService.getAllCategories()
.subscribe(
data => {
this.myCategories = data;
console.log(data);
},
error => {
console.log(error);
});
}
newJob() {
this.submitted = false;
this.job = {
category: '',
endDated: '',
email: '',
published: false
};
}
}
W narzędziach developerkich w chrome w zakładce network wyświetla mi że się pobrała tablicca z kategoriami z mojego api ale nie wyświetla mi na stronie ich. Dopiero uczę się angulara i pewnie gdzieś zamotałe, :)