0

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.

3
  • if i understand, you should de-html-escape the operator input value from &gt; to > etc. in your javascript script Commented Dec 17, 2015 at 0:06
  • I used > before &gt. Didn't make a difference Commented Dec 17, 2015 at 0:30
  • 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) Commented Dec 17, 2015 at 14:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.