S
S
Sergey2015-11-10 16:17:15
JavaScript
Sergey, 2015-11-10 16:17:15

Set keyKode on window angularjs?

// пример на jquery
$(window).keydown(function(e){
  if(e.keyCode == 27){ // esc
  //  Какое-то событие 
 }
});
;
How to set such code in angularjs if $scope.showFon = true; and disable if $scope.showFon = false;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Facetrollex, 2015-11-10
@Sergamers

var watcher = $scope.$watch('showFon', function (prev, new) {
            if(new === true) {
                   angular.element($window).bind('keydown', function () {
                           //do something
                    });
             } else { //dispatch keydown on window}
})


$scope.$on('$destroy', function () { watcher(); })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question