I've to populate table dynamically on value change of one textbox. Everytime when I change value of textbox json rebuilds dynamically on textbox parameters and that json populate datatable. I've achived the same in jquery and javascript But I'm unable to achieve this in Angular js, Please find my code snippet below:
HTML:`<table>
<thead>
<tr>
<th colspan="2">Year</th>
<th>Principal (X)</th>
</tr>
</thead>
<tbody data-ng-repeat="t in emi.generateJson()">
<tr>
<td>{{ t.parentDataNode.tenure }}</td>
<td>{{ t.parentDataNode.principal }}</td>
</tr>
</tbody>
</table>`
JS: `var mainApp = angular.module("mainApp", []);
mainApp.controller('emiController', function($scope) {
$scope.emi = {
amount: 2000000,
tenure: 1,
interest: 9.85,
emiValue:0.00,
totalPaymentValue:0.00,
advanceEmi:false,
generateJson: function() {
var sitePersonel = {};
var tabledata = []
sitePersonel.tabledata = tabledata;
for(var i=0;i<2;i++) {
var arrParent = new Array();
arrParent.push(2015);
arrParent.push(1311418.9*i);
sitePersonel.tabledata.push({});
sitePersonel.tabledata[i].parentDataNode = returnParentData(arrParent);
for(var j=0;j<12;j++) {
var arr = new Array();
arr.push("May");
arr.push(159275.61*j);
sitePersonel.tabledata[i].parentDataNode.childDataNode[j] = returnChildData(arr);
}
}
console.log(JSON.stringify(sitePersonel));
return sitePersonel;
}
}
});`
at Error (native)`
I know that calling function in ng-repeat is not good approach, But my requirement is something like that I have to call this function here. Can someone please suggest me the right approach to form the data table dynamically with a json that is dynamically forming every time on change of some textbox etc.
Thanks
Jitender