Hello fellow programmer,
after i make an API call i convert the JSON to an array.
This array will display in an Component inside an HTML table, after you pressed the "edit" button the Component will change his content from an HTML table to an HTML form, where you can edit the Data, which Data you can send back to the API server.
component.html
<div *ngFor="let rule of generateArray(gutschein['ruleset_list']['rulesets']); let i = index" >
<div class="form-group">
<label>Rule: </label> <input type="text" class="form-control" id="rule{{i}}"
requierd
[(ngModel)]="rule['condition']['expression']" name="rule" #rule="ngModel">
<div [hidden]="rule.valid || rule.pristine" class="alert alert-danger">
Rule is not valid
</div>
</div>
<div class="form-group">
<label>Discount: </label> <input type="text" class="form-control" id="discount{{i}}"
requierd
[(ngModel)]="rule['results']['results'][i+1]['calculation']" name="discount" #discount="ngModel">
<div [hidden]="discount.valid || discount.pristine" class="alert alert-danger">
Discount is not valid
</div>
</div>
component.ts
generateArray(obj) {
return Object.keys(obj).map((key) => { return obj[key] });
}
it seems like the ngModel
cant reache my this.rule['condition']['expression']
Data.
If i changed it to this.rule['condition']
it works perfectly.
Any Idea how I can fixed this problem? I would be thankfull for an explanation not only the fixed code.
JSON
{
"id": "1",
"code": "A1234",
"valid": null,
"ruleset_list": {
"rulesets": {
"1": {
"id": "1",
"voucher_id": "1",
"condition": {
"expression": "shop.totalamount > `15` && current_datetime < `1490021400`"
},
"results": {
"results": {
"1": {
"id": "1",
"value_path": "shop.totalamount",
"calculation": "#VALUE * 0.9",
"new_value": null
}
}
}
},
"2": {
"id": "2",
"voucher_id": "1",
"condition": {
"expression": "shop.totalamount > `20` && current_datetime < `1490021400`"
},
"results": {
"results": {
"2": {
"id": "2",
"value_path": "shop.totalamount",
"calculation": "#VALUE * 0.8",
"new_value": null
}
}
}
}
}
}
}