I pull data from an API that works fine if I don't bind the value of my JSON parameter number to the [value] tag. see example:
WORK (data obtained from the API is selected in the option)
<select [(ngModel)]="data.from.api.one" class="form-control">
<option *ngFor="let c of subdimension" [value]="c.name">{{ c.name }}</option>
</select>
DOES NOT WORK (data not selected, and the first option is zero)
<select [(ngModel)]="data.from.api.one" class="form-control">
<option *ngFor="let c of subdimension" [value]="c.value">{{ c.name }}</option>
</select>
JSON object:
subdimension = [{'name': 'sub1','value': 2 },
{'name': 'sub2','value': 4 },
{'name': 'sub3','value': 8}]
What I want to do is bind a numeric value to some select items, and then sum them up as:
data.from.api.one + data.from.api.two ...
EDIT:
Component code from data.from.api
constructor (public dataService:DataService){
this.dataService.getData().subscribe(datas => {
this.datas = datas;
});
}
getData(){
return this.http.get('https://api.url/').map(res => res.json());
}
datas:Data[];
data = {
from:{api:{one:'',two:'',three:''}}
}
source
share