2016-10-13 52 views
0

我有我的控制器這段代碼的應用程序離子如果聲明離子,角JS

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

我需要添加的,如果在該消息的變化,如果testScore var爲> 50 但我是初學者在離子或角js ...任何好人都可以幫我嗎?

回答

1

你可以改變你的模板:

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' 
}); 

或者,甚至可能更好,處理它的模板角的方式:

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' 
}); 
0

你可以像這樣

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

你的例子:

<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> 

更多從這裏的例子:

if else statement in AngularJS templates