Vinicius Saran Vinicius Saran - 1 year ago 99
AngularJS Question

Variable inside controller scope

I have the following json:

"id": "026001",
"description": "Drop Forged Double Coupler",
"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 Source

You need to update from

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


$scope.newHireRate = $scope.product[userLogged].hireRate * qtd;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download