angular.js listen for keypress as shortcut for button

前端 未结 5 845
离开以前
离开以前 2021-01-02 08:03

My first ever angular application is a pretty basic survey tool. I have multiple choice questions, with a button for each answer and a basic function that logs each answer o

5条回答
  •  走了就别回头了
    2021-01-02 08:20

    Catch the event emitted by the rootscope in your controller:

    $rootScope.$on('keypress', function (e, a, key) {
        $scope.$apply(function () {
            $scope.key = key;
        });
    })
    

    key is then yours to use in the controller.

    Here's a fiddle

提交回复
热议问题