如何在Angular.js中只显示一次通知弹出窗口?

时间:2017-01-05 12:14:28

标签: angularjs

我正在研究Angularjs。我只需要显示一次通知弹出窗口,但是当我在文本框中输入值时,我的弹出窗口会多次显示。

这是我的一段代码。

  $scope.AmountAddition = function() {
                var contributionAmt = $scope.search_form.amount;
                $scope.search_form.paymentBasic.totalContributionAmountCollected = $scope.search_form.amount;
                 if(contributionAmt >= 50000)
                {
                     notificationFactory.info("Kindly enter Pancard number");
                }
           } 

当我输入金额超过50000时,如何只显示一次弹出窗口?

3 个答案:

答案 0 :(得分:1)

您可以在$scope.isFirstTime的开头添加标记controller,并在显示通知后进行设置

if(contributionAmt >= 50000 && $scope.isFirstTime)
{
    notificationFactory.info("Kindly enter Pancard number");
    $scope.isFirstTime = false;
}

答案 1 :(得分:0)

使用布尔变量来了解弹出窗口是否已打开过一次:

$scope.alreadyOpenned = false; 

$scope.AmountAddition = function() {
    var contributionAmt = $scope.search_form.amount;
    $scope.search_form.paymentBasic.totalContributionAmountCollected = $scope.search_form.amount;
    if(contributionAmt >= 50000 && !$scope.alreadyOpenned) {
        $scope.alreadyOpenned = true;
        notificationFactory.info("Kindly enter Pancard number");
    }
} 

答案 2 :(得分:0)

你可以使用它。

$scope.isOpenned = false;     
$scope.AmountAddition = function() {
    var contributionAmt = $scope.search_form.amount;
    $scope.search_form.paymentBasic.totalContributionAmountCollected = $scope.search_form.amount;
    if(contributionAmt >= 50000 && !$scope.alreadyOpenned) {        
        notificationFactory.info("Kindly enter Pancard number");
        $scope.isOpenned = true;
    }
} 

但是你的价值超过50000,弹出窗口首次出现。下次你给40000并再次给出50000以上时,弹出窗口将不显示。

如果您需要以上情况,可以使用if else ..

if(contributionAmt >= 50000 && !$scope.alreadyOpenned) {        
            notificationFactory.info("Kindly enter Pancard number");
            $scope.isOpenned = true;
        }else{
 $scope.isOpenned = false;
}