mardi 13 décembre 2016

How to test the scope function inside the directive?

I want to test the scope.OnEditButtonClick function with clicked event passed as the function parameter, how do i do this?

angular.module('directiveNameSpace').directive(
        'nameEditable',
        function($rootScope, $timeout, BlaBlaService) {
            return {
                require : '?ngModel',
                link : function(scope, element, attrs, ngModel) {
                    var el = element[0];

                    //edit button click event handle
                    scope.OnEditButtonClick = function(e){
                        scope.isEdit = true;
                        element.attr('contenteditable', scope.isEdit);
                        element.focus();
                        var s = window.getSelection(), r = document
                                .createRange();
                        r.setStart(el, 0);
                        r.setEnd(el, 0);
                        s.removeAllRanges();
                        s.addRange(r);
                        e.preventDefault();
                        e.stopPropagation();
                    };
              };
        });

Aucun commentaire:

Enregistrer un commentaire