Reputation: 5
I have a JSON variable in my StudentService.ts and I want to populate my select options from these JSON.
My service:
careers : {};
constructor(private http: HttpClient) {
this.selectedStudent = new Student();
this.careers = [
{"id":"itic", "name":"Sistemas"},
{"id":"itic", "name":"Sistemas"},
{"id":"itic", "name":"Sistemas"},
];
}
My template.html
<p>{{ studentService.careers | json }}</p>
<div class="input-field col s12">
<select>
<option ng-repeat="career in studentService.careers">{{career.name}}</option>
</select>
<label>Materialize Select</label>
</div>
The first line in template.html
works, and shows my JSON, but I can't replicate that in my select.
Upvotes: 0
Views: 44
Reputation: 222572
Angular does not have ng-repeat
, the corresponding syntax is ngFor
, you need to change it using ngFor,
<select>
<option *ngFor="let career of studentService.careers">{{career.name}}</option>
</select>
Upvotes: 3