Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

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="&gt">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="&lt">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.

share|improve this question
    
if i understand, you should de-html-escape the operator input value from &gt; to > etc. in your javascript script – Nikos M. 16 hours ago
    
I used > before &gt. Didn't make a difference – Romano 16 hours ago
    
i am implying to use it in the script, not in html value. In other words, when the script reads the operator value to read it as > insead of &gt; 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.