I have created a Angular 2 service which reads a local json using http (could be rest service call later) and returns an Observable.
@Injectable()
export class WorkflowDataService {
constructor(private http: Http) { }
getProcessTemplates(): Observable<Response> {
return this.http.get("/assets/jsons/process-templates.json");
}}
the json that is being read looks like this
{
"process-templates": [
{
"name": "ABC",
"desc": "ABC"
},
{
"name": "XYZ",
"desc": "XYZ"
},
{
"name": "PQR",
"desc": "PQR"
}
]
}
My goal is to show the values of name attributes in a dropdown. So, the dropdown should have - ABC, XYZ, PQR.
So in my component, I am calling this service -
processTemplates: Observable<Response>;
ngOnInit( ) {
this.workflowDataService.getProcessTemplates()
.subscribe(function(response) {
this.processTemplates = response.json();
console.log(this.processTemplates);
});
}
In the console.log, I see the below output
how can I get the output in a format which can be rendered in a drop down
<select class="form-control dropdown" (ngModel)="processTemplate"
name="processTemplate" id="processTemplate" required>
<option *ngFor="let processTemplate of processTemplates">
{{ processTemplate.name }}
</option>
</select>