0

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.

Dale K
  • 25,246
  • 15
  • 42
  • 71
MoisesH18
  • 5
  • 2

1 Answers1

3

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>
Lazar Ljubenović
  • 18,976
  • 10
  • 56
  • 91
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • Before put question, I tried that method but it not worked. After all night, I realize it was a Materialize CSS framework error, apparently "M.AutoInit();" does not autoInit all elements, Select Forms one of them. Thank you! – MoisesH18 Aug 11 '18 at 16:18