0

I have this code in my controller on ionic app

// Shows test score to the user
alertPopup = $ionicPopup.alert({
    title: user + message,
    template: 'Your score: ' + testScore + '%',
    okText: Paid ? 'View test results' : 'Close'
});

i need to add an if where the message change if testScore var is > 50. But i'm a beginner in ionic or angular js... Can any good guy give me help?

Mohamed Gara
  • 2,665
  • 3
  • 13
  • 19
rubenSousa
  • 261
  • 8
  • 23

2 Answers2

1

You can just change your template:

var template = '<div>Your score: ' + testScore +'%</div>';
if (testScore > 50) {
    template += "<div>This only shows if testScore is higher than 50</div>";
}

alertPopup = $ionicPopup.alert({
    title: user + message,
    template: template,
    okText: Paid ? 'View test results' : 'Close'
});

Or, probably even better, handle it in the template in angular's way:

alertPopup = $ionicPopup.alert({
    title: user + message,
    scope: $scope, // the $scope object with the testScore property
    template: '<div>\
                   Your score: {{ testScore }}%>\
               </div>\
               <div ng-if="testScore > 50">\
                   This only shows if testScore is higher than 50\
               </div>',
    okText: Paid ? 'View test results' : 'Close'
});
devqon
  • 13,818
  • 2
  • 30
  • 45
0

you can do like this

{{ConditionVar ? 'varIsTrue' : 'varIsFalse'}}

your example:

<div ng-if="testScore < 50">
    <!-- code to render a large video block-->
</div>
<div ng-if="testScore > 50">
    <!-- code to render the regular video block -->
</div>

more examples from here :

if else statement in AngularJS templates

Community
  • 1
  • 1
Vitaly Menchikovsky
  • 7,684
  • 17
  • 57
  • 89