I'm pulling data from an API, which is going fine unless I bind my JSON option number value into the [value] tag. see example:
WORKING (data got from API is selected on the option)
<select [(ngModel)]="data.from.api.one" class="form-control">
<option *ngFor="let c of subdimension" [value]="c.name">{{ c.name }}</option>
</select> <!-- select with c.name on value -->
NOT WORKING (data is not selected and the first option is null)
<select [(ngModel)]="data.from.api.one" class="form-control">
<option *ngFor="let c of subdimension" [value]="c.value">{{ c.name }}</option>
</select> <!-- select with c.value on value -->
JSON object:
subdimension = [{'name': 'sub1','value': 2 },
{'name': 'sub2','value': 4 },
{'name': 'sub3','value': 8}]
What I want to do is to bind a number value into some selects and then sum all of them like:
data.from.api.one + data.from.api.two...
EDIT:
Component code from the 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:''}}
}