Reputation: 523
I'm working in a app with Angularjs, node and SQL SERVER. I want to calculate the result of a condition that comes from a database field.
var chk = angular.fromJson(item.CHK1);
item.chk1
is a field comming from the database, and its equal to {"validation_cal":"item.QNT_PROPUESTA > 1000","validation_type":"BLOCK","description":"Stock mas de un año"}
So chk.validation_cal
is equal to item.QNT_PROPUESTA > 1000
and item.QNT_PROPUESTA
is equal to 1200
I've tried:
console.log($rootScope.$eval(chk.validation_cal));
The result always is "false
"
I supposed the problem is that Angular is not really doing the calculation of the condition.
Any help will be appreciate.
Thanks in advance.
Upvotes: 0
Views: 46
Reputation: 26
It seems that the problem consists of that the scope doesn´t know the value of the field item.QNT_PROPUESTA. The function $eval is trying to evaluate the expression item.QNT_PROPUESTA > 1000 but before this value has to be in the rootScope.
I have tried this and it works:
var chk = angular.fromJson(item.CHK1);
$rootScope.item = { QNT_PROPUESTA : 1200 };
console.log($rootScope.$eval(chk.validation_cal)); // true
Upvotes: 1