我在角度6方面很菜鸟。我在StudentService.ts中有一个JSON变量,我想从这些JSON中填充选择选项。
我的服务:
careers : {};
constructor(private http: HttpClient) {
this.selectedStudent = new Student();
this.careers = [
{"id":"itic", "name":"Sistemas"},
{"id":"itic", "name":"Sistemas"},
{"id":"itic", "name":"Sistemas"},
];
}
我的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>
template.html中的第一行有效,并显示了我的JSON,但我无法在我的选择中复制它。 谢谢!
答案 0 :(得分:3)
Angular没有 ng-repeat
,相应的语法为 ngFor
,您需要使用ngFor进行更改,
<select>
<option *ngFor="let career of studentService.careers">{{career.name}}</option>
</select>