2014-02-27 85 views
3

我顯示以下代碼作爲成功更新記錄。用戶保持在&的同一個編輯部分上,看到這個msg剛好在update button之上。隱藏成功消息

我希望這個msg消失,因爲用戶仍然可以編輯記錄。

如何隱藏這個success msg?所以你的AJAX後,沒有這個標誌設置爲true - -

<div class="label label-success" data-ng-show="updateStatus"> 
    <span class="glyphicon glyphicon-thumbs-up icon-white"></span>updated! 
</div> 
+0

只是分配falsy價值,你的updateStatus範圍變量。 –

+0

在哪裏分配這個值? – Anup

+0

你想在超時後(setTimeout())隱藏消息還是用戶編輯了一些東西? –

回答

0

當您設置$scope.updateStatustrue該消息只顯示其保留爲false和您的郵件永遠不會顯示。

1

只需添加這您添加成功的消息

  setTimeout(function(){$('.label-success').slideUp();},3000); //slidup after 3 second 

上面的代碼會後3秒

+0

作品......但僅限於第一次.....所以如果用戶再次編輯一些東西......「msg」不會顯示出來... – Anup

+0

使成功id的ID ,然後使用該id爲slidingUp函數,id應該不同於不同的消息div – sanjeev

+0

更容易的是在html中獲得成功'div',而不是通過ajax,然後使用slideDown()來顯示消息,並且上面的代碼在3秒後隱藏消息,這樣每個成功消息將顯示相同的'div' – sanjeev

0

效果基本show的消息後嘗試這樣

<div class="col-sm-6 form-group"> 
       <label for="text">Text</label> 
       <input class="form-control input-lg" type="text" id="text" required name="text" ng-model="user.text" **ng-change="OnChange()"** placeholder="Enter your text"> 
       </select> 
      </div> 
      <div class="col-sm-6 form-group"> 
       <label for="email">Email Address</label> 
       <input class="form-control input-lg" type="email" id="email" required name="email" ng-model="user.email" **ng-change="OnChange()"** placeholder="Enter your email"> 
      </div> 

的js側

$Scope.OnChange=function(){ 
    $scope.updateStatus=false; 
    $scope.$apply(); 
    } 

調用此ng-change="OnChange()"到所有領域

或嘗試此警告標籤。您可以刪除警報不需要的時間。

<div ng-controller="AlertDemoCtrl"> 
    <alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{alert.msg}}</alert> 
    <button class='btn btn-default' ng-click="addAlert()">Add Alert</button> 
</div> 

js代碼

function AlertDemoCtrl($scope) { 
    $scope.alerts = [ 
    { type: 'danger', msg: 'Oh snap! Change a few things up and try submitting again.' }, 
    { type: 'success', msg: 'Well done! You successfully read this important alert message.' } 
    ]; 

    $scope.addAlert = function() { 
    $scope.alerts.push({msg: "Another alert!"}); 
    }; 

    $scope.closeAlert = function(index) { 
    $scope.alerts.splice(index, 1); 
    }; 

} 

演示:http://plnkr.co/edit/?p=preview