3

I'm trying to write a directive in angularJS which allow to open this https://github.com/Mottie/Keyboard/ on-screen keyboard on click a button or image. So far I made based on this topic : Update AngularJS models from a jQuery plugin with a "on change" callback, directive which open a keyboard on click at input field. Can anyone help me with it ?

app.directive('keyboard',function(){
  return {
    require : '?ngModel',
    restrict : 'C',
    link : function(scope,element,attrs,ngModelCtrl){
      if(!ngModelCtrl){
        return;
      }

      $(element).keyboard({
        stickyShift: false,
        usePreview: false,
        autoAccept: true,

        change: function(e, kb, el) {
            if(!scope.$$phase && !scope.$root.$$phase)
            {
                scope.$apply(function(){
                    ngModelCtrl.$setViewValue(el.value);
                }); 
            }
        }
    });
    }
  };
});
Community
  • 1
  • 1
Wojtek
  • 233
  • 1
  • 4
  • 16

1 Answers1

1

You should be able to just bind jQuery click event in link function:

element.click(function(){
    element.getkeyboard().reveal();
});
jcubic
  • 61,973
  • 54
  • 229
  • 402