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?

2 Answers 2

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'
});
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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.