Vinicius Saran Vinicius Saran - 5 months ago 18
AngularJS Question

Variable inside controller scope

I have the following json:

{
"id": "026001",
"description": "Drop Forged Double Coupler",
"CASHCUST01": {
"hireRate": "0.01500",
"saleRate": "2.50000"

},
"SMITH00010": {
"hireRate": "0.02500",
"saleRate": "1.50000"

},
"imageUrl": "images/fitting.jpg"
}


My controller:

var userLogged = 'SMITH00010';

$scope.updateValue = function(qtd) {
$scope.newHireRate = $scope.product.{{userLogged}}.hireRate * qtd;
}


I want to show the right price of the product based on what user is logged in.

It's not working this way, I'm sure there is a way to do it, anyone can help me?

Answer

You need to update from

$scope.newHireRate = $scope.product.{{userLogged}}.hireRate * qtd;

to

$scope.newHireRate = $scope.product[userLogged].hireRate * qtd;