2015-01-13 28 views
0

我有一個jQuery的關鍵事件監聽器,它尋找Ctrl + C事件。我的問題在下面評論。帶角度的jQuery鍵事件

jQuery(window).on('keydown', function(e){ 

    if(e.ctrlKey && e.which == '67') 
    { 
     // console.log('pressed'); This works 
     // $scope.closeShareBar(); This works 
     $scope.showNotif('The URL has been copied to your clipboard', null, true); // This DOES NOT work 
    } 

}); 

$scope.showNotif('The URL has been copied to your clipboard', null, true); // This works 

爲什麼它不起作用? $scope.showNotif()是我寫的顯示通知的函數。

編輯
我希望我已經清楚地表明$scope.closeShareBar();作品沒有$apply()。爲什麼只有這個工作呢?這個角度也不是?

編輯2

$scope.showNotif = function(text, status, closeEnabled, quick){ 
    $scope.notif_text = text; 
    $scope.notif = status || 'show'; 
    if (closeEnabled == true) 
    { 
     $timeout.cancel($scope.timer); 
     $scope.timer = $timeout(function(){ 
      $scope.notif = ''; 
     }, 3000); 
    } 
    if (quick == true) 
    { 
     $scope.notif = ''; 
    } 
} 


$scope.closeShareBar = function(){ 

    // $scope.shareLink = 'http://localhost:3000/single-signal/'+id; 
    angular.element(document.querySelectorAll('.signal_wrapper .signal_data')).removeClass('share_overlay'); 
    angular.element(document.querySelectorAll('.signal_wrapper .sb_status .share')).removeClass('hide'); 
    angular.element(document.querySelectorAll('.signal_wrapper .sb_status .close')).addClass('hide'); 

} 
+0

如果設置了調試斷點,是否到達了故障線路? – isherwood

+0

如果您正在尋找showNotif中發生的某些作用域綁定更新,則可能需要執行$ scope。$ apply()。 – PSL

+0

只有在更新綁定到視圖的範圍屬性時,您才需要scope.apply。沒有看到'showNotif'是否很難提供幫助。 – PSL

回答

0

你做一些事情的角度以外任何時候,你需要通知它,你已經做了改變。所以就在你的$ scope.showNotif之後,你需要做一個$ scope。$ apply();

$scope.showNotif(...); 
$scope.$apply();