Adding function to Json Array in AngularJS -


i have json object returned webapi,

[{name:john,val1:10,val2:20,val3:0}, {name:jane,val1:50,val2:200,val3:0}] 

i store array in "$scope.dtarray" bound ui(textboxes) using ng-repeat. before binding happens want assign function add values shown here

this.val3 = function() {return number(this.val1) + number(this.val2) }; 

for each object in array. when ever user changes val1 , val2 text boxes, value changes val3 automatically.

following ui markup...

<div ng-repeat="cnt in dtarray track $index">     <table style="border-style: solid;">         <tr>             <td>                 <input type="text" ng-model="cnt.name">                 <input type="text" ng-model="cnt.val1">                 <input type="text" ng-model="cnt.val2">                 <input type="text" ng-model="cnt.val3()">             </td>         </tr>     </table> </div> 

the function not getting called in change of value in val1 or val2.

any appreciated.

thanks.

try below html code instead of code

<div ng-repeat="cnt in dtarray track $index">     <table style="border-style: solid;">         <tr>             <td>                 <input type="text" ng-model="cnt.name">                 <input type="text" ng-model="cnt.val1">                 <input type="text" ng-model="cnt.val2">                 <input type="text" ng-init="cnt.val3=val3(this)" ng-model="cnt.val3">             </td>         </tr>     </table> </div> 

also val3 function should used $scope.functionname()

like :

$scope.val3 

try code below instead of code

$scope.val3 = function(context) {return number(context.val1) + number(context.val2) }; 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -