I have some trouble with creating a price Alarm for my AngularJS app. I want the user to put in an alarm value and an operator for if the alarm just trigger below or above x price.
<ion-radio name="operator" ng-model="statement" value=">">Alarm if price is Higher than {{ alarmValue }} <i class="ion-arrow-graph-up-right"></i></ion-radio>
<ion-radio name="operator" ng-model="statement" value="<">Alarm if price is Lower than {{ alarmValue }} <i class="ion-arrow-graph-down-left"></i></ion-radio>
The problem is that AngularJS doesn't see the operator input as a real operator but more like a string of text.
$scope.alarms = AlarmService.list(); $scope.saveAlarm = function(market){
$scope.newalarm = {'currency':market,
'alert' :$scope.alarmValue,
'statement':$scope.statement};
AlarmService.save($scope.newalarm);
console.log($scope.newalarm);
The $scope.statement is the operator. The AlarmValue is is the trigger price and currency is as example EURUSD
$scope.multicalculation = function(){
if ($scope.newalarm.alert !== 'undefined')
{ //count how many alarms
for(var i = 0; i < $scope.alarms.length; i++)
{ //Count how many markets. Example EURUSD, GBPUSD, NZDUSD.
for(var n = 0; n < $scope.alarmingMarket.length; n++)
{
if ($scope.alarms[i].currency == $scope.alarmingMarket[n] && $scope.m_rate < $scope.alarms[i].alert)
{
//execute something (Push notify)
}
}
}
} };
This would gave something like (if EURUSD == EURUSD && liveprice < alarmprice
Execute pushnotify.
The reason I check if EURUSD == EURUSD.. I check if the market I am montering is equel to the alarm if I have put in. If monitor EURUSD and have a GBPUSD alarm that would give a false alarm for the user. Yes, I check multiple markets with multiple alarms. It's kinda tricky since I'm new in angular.
I hope anyone has/knows a solution for the operator that I save in the multi array, that I would like to be shown as an operator instead of a real string. If anyone knows how to simplify my code, that would be nice too.
>
to>
etc. in your javascript script – Nikos M. 16 hours ago>
insead of>
Note that you cannot put>
as a value in html (it is invalid xml) so it must be html-encoded (and thus html-decoded in the script) – Nikos M. 2 hours ago