I am trying to to update the attribute of an onbject in angularjs array of object.
I have the folowing array of object:
$scope.formes= [
{id: 0, geo: 0,cx:0, cy:0, b:0, h:0, r:0, d:0, a:0, ax:0, ay:0, val: 0}
];
The values of each attribute are set to 0 by default until the user type in a new value in a field. Some values are updated after the user add a new objet or hit a button. This app is used to calculate the center of basic geometric shapes and there moments. Just fyi.
This is the function that is running when the user add an object.
$scope.ajoutForme = function(){
$scope.formes.a = parseInt($scope.formes.b) * parseInt($scope.formes.h); /// not working
$scope.formes.push({
id: $scope.nbrForme++ //just adding and new id
});
}
Before I add the objet I want to update some values with calculations. For exemple in this case I what to set the value of a with b*h.
I have try
$scope.formes[nbrForme].h = parseInt($scope.formes[nbrForme].b) * parseInt($scope.formes[nbrForme].h); //This is working but only the first time I press the button??
nbrForme is = to the id of the element I am working on and gets incremented when I add a new object.
Complete Controler
var moment = angular.module('moment',[]);
var nbrForme = 0;
moment.controller('momentCtrl', ['$scope', function($scope) {
$scope.nbrForme = nbrForme;
$scope.formes= [
{id: 0, geo: 0,cx:0, cy:0, b:0, h:0, r:0, d:0, a:0, ax:0, ay:0, val: 0}
];
$scope.ajoutForme = function(){
$scope.formes[nbrForme].a = parseInt($scope.formes[nbrForme].b) * parseInt($scope.formes[nbrForme].h); /// only work once
$scope.formes.push({
id: $scope.nbrForme++
});
}
}
}]);