0

I have make image slider in angularjs with google material. My slider is working but I have two issue

  1. I could not bind keypress
  2. My images are sliding but both side together and then first hide after few seconds

Some code is over here

$scope.onKeyUp = function (keyCode) {
                console.log("I am here;")
                if (keyCode === LEFT_ARROW) {
                    $scope.prevSlide;
                } else if (keyCode === RIGHT_ARROW) {
                    $scope.nextSlide;
                }
            }

and full codepen is https://codepen.io/milindsaraswala/pen/yJaYpe

Kindly somebody help, what can be the issue.

Milind
  • 1,855
  • 5
  • 30
  • 71

1 Answers1

1

Ok, there are a few things that you would need to change.

First, you ought to know that keypress/keydown would only work on elements which can receive focus (like input elements).

A hack to do that is to specify tabindex on your element. AngularJS ng-keydown directive only working for <input> context?

<div class="slider" tabindex="0" ng-keyup="onKeyUp($event)"  flex></div>

Secondly, you need to use keyup event instead of keypress, as it seems that keypress is deprecated.

This is the updated codepen. https://codepen.io/gaurav5430/pen/xOEXzG/

console.log is being called for keypress now (not sure if your logic is working or not)

You will need to click once on the slider to focus it (or use keyboard to focus)

Community
  • 1
  • 1
gaurav5430
  • 12,934
  • 6
  • 54
  • 111