Как я могу исправить следующую ошибку?Ошибка типа: f [s] не является функцией - PullRequest
0 голосов
/ 29 ноября 2018
//when open application then this error show, How can i fix this please explain me.        
TypeError: keyboard[extension] is not a function
at Object.attach (ng-virtual-keyboard.js:104)
at Object.link (ng-virtual-keyboard.js:133)
at angular.js:1365
at angular.js:11229
at invokeLinkFn (angular.js:11235)
at nodeLinkFn (angular.js:10554)
at compositeLinkFn (angular.js:9801)
at nodeLinkFn (angular.js:10548)
at compositeLinkFn (angular.js:9801)
at compositeLinkFn (angular.js:9804)

"<input type="text" id="login" name="login" ng-virtual-keyboard="" placeholder="Employee ID" class="fadeIn second ng-pristine ng-untouched ng-valid ng-isolate-scope ui-keyboard-input ui-widget-content ui-corner-all" ng-model="auth.empID" required="" aria-haspopup="true" role="textbox">"

// This is HTML code
 <input type="text"id="login"name="login" ng-virtual-keyboard placeholder="Employee ID" class="fadeIn second" ng-model="auth.empID" required>

<input type="password" id="password" ng-virtual-keyboard placeholder="Password" class="fadeIn third" ng-model= "auth.password" required>
<input ng-click="signin(auth)" type="submit" class="fadeIn fourth" value="Log In">

// это моя функция в angularjs

            $scope.signin = function(valid){
                if(valid){
                    var sign = customerService.validUser($scope.auth);
                        sign.then(function(data){
                            if(data.status == "success"){
                                $scope.val = data;
                                $localStorage.val = data;
                                if(data.userdata.usertype == "admin"){
                                    $location.path("/admin");
                                    $rootScope.$emit("callAdmin", {"mydata":data});
                                }else if(data.userdata.usertype == "user"){
                                    $location.path("/product");
                                    $rootScope.$emit("callClient", {"mydata":data});
                                }

                                toastr.info("Welcome !");
                            }else{
                                toastr.error("Invalid Credential !");
                            }
                        })
                }else{
                    toastr.error("Invalid Credential !");
                }
            };

// это ng-virtual-keyboard.js

/ ** * ng-virtual-keyboard *Виртуальный интерфейс клавиатуры AngularJs на основе Mottie / Keyboard * @version v0.3.3 * @author antonio-spinelli * @link https://github.com/antonio-spinelli/ng-virtual-keyboard * @license MIT * / (функция (угловая) {

        angular.module('ng-virtual-keyboard', [])

        .constant('VKI_CONFIG', {

        })

        .service('ngVirtualKeyboardService', ['VKI_CONFIG', function(VKI_CONFIG) {
            var clone = function(obj) {
                var copy;

                // Handle the 3 simple types, and null or undefined
                if (null === obj || 'object' !== typeof obj) {
                    return obj;
                }


                // Handle Date
                if (obj instanceof Date) {
                    copy = new Date();
                    copy.setTime(obj.getTime());
                    return copy;
                }

                // Handle Array
                if (obj instanceof Array) {
                    copy = [];
                    for (var i = 0, len = obj.length; i < len; i++) {
                        copy[i] = clone(obj[i]);
                    }
                    return copy;
                }

                // Handle Object
                if (obj instanceof Object) {
                    copy = {};
                    for (var attr in obj) {
                        if (obj.hasOwnProperty(attr)) {
                            copy[attr] = clone(obj[attr]);
                        }
                    }
                    return copy;
                }

                throw new Error('Unable to copy obj! Its type isn\'t supported.');
            };

            var executeGetKeyboard = function(elementReference) {
                var keyboard;
                var element = $(elementReference);
                if (element) {
                    keyboard = $(elementReference).getkeyboard();
                }
                return keyboard;
            };

            return {
                attach: function(element, config, inputCallback) {
                    var newConfig = clone(VKI_CONFIG);

                    config = config || {};

                    for (var attr in config) {
                        if (config.hasOwnProperty(attr)) {
                            newConfig[attr] = config[attr];
                        }
                    }

                    newConfig.accepted = config.accepted || inputCallback;

                    if (config.autoUpdateModel) {
                        newConfig.change = config.change || inputCallback;
                    }

                    if (newConfig.events) {
                        var addEventMethod = function(eventName) {
                            return function(e, kb, el) {
                                newConfig.events[eventName](e, $(this).data('keyboard'), this);
                            };
                        };

                        for (var eventName in newConfig.events) {
                            $(element).on(eventName, addEventMethod(eventName));
                        }
                    }

                    var keyboard = $(element).keyboard(newConfig);

                    if (keyboard && newConfig.extensions) {
                        for (var extension in newConfig.extensions) {
                            var extConfig = newConfig.extensions[extension];
                            if (extConfig) {
                                keyboard[extension](extConfig);
                            } else {
                                keyboard[extension]();
                            }
                        }
                    }
                },
                getKeyboard: function(elementReference) {
                    return executeGetKeyboard(elementReference);
                },
                getKeyboardById: function(id) {
                    return executeGetKeyboard('#' + id);
                }
            };
        }])

        .directive('ngVirtualKeyboard', ['ngVirtualKeyboardService', '$timeout',
            function(ngVirtualKeyboardService, $timeout) {
                return {
                    restrict: 'A',
                    require: '?ngModel',
                    scope: {
                        config: '=ngVirtualKeyboard'
                    },
                    link: function(scope, elements, attrs, ngModelCtrl) {
                        var element = elements[0];

                        if (!ngModelCtrl || !element) {
                            return;
                        }

                        ngVirtualKeyboardService.attach(element, scope.config, function(e, kb, el) {
                            $timeout(function() {
                                ngModelCtrl.$setViewValue(element.value);
                            });
                        });

                        scope.$on('$destroy', function() {
                            var keyboard = $(element).getkeyboard();
                            if (keyboard) {
                                keyboard.destroy();
                            }
                        });
                    }
                };
            }
        ]);

        })(angular);

1 Ответ

0 голосов
/ 29 ноября 2018
/**
 * ng-virtual-keyboard
 * An AngularJs Virtual Keyboard Interface based on Mottie/Keyboard
 * @version v0.3.3
 * @author antonio-spinelli <antonio.86.spinelli@gmail.com>
 * @link https://github.com/antonio-spinelli/ng-virtual-keyboard
 * @license MIT
 */
(function (angular) {

angular.module('ng-virtual-keyboard', [])

.constant('VKI_CONFIG', {

})

.service('ngVirtualKeyboardService', ['VKI_CONFIG', function(VKI_CONFIG) {
    var clone = function(obj) {
        var copy;

        // Handle the 3 simple types, and null or undefined
        if (null === obj || 'object' !== typeof obj) {
            return obj;
        }


        // Handle Date
        if (obj instanceof Date) {
            copy = new Date();
            copy.setTime(obj.getTime());
            return copy;
        }

        // Handle Array
        if (obj instanceof Array) {
            copy = [];
            for (var i = 0, len = obj.length; i < len; i++) {
                copy[i] = clone(obj[i]);
            }
            return copy;
        }

        // Handle Object
        if (obj instanceof Object) {
            copy = {};
            for (var attr in obj) {
                if (obj.hasOwnProperty(attr)) {
                    copy[attr] = clone(obj[attr]);
                }
            }
            return copy;
        }

        throw new Error('Unable to copy obj! Its type isn\'t supported.');
    };

    var executeGetKeyboard = function(elementReference) {
        var keyboard;
        var element = $(elementReference);
        if (element) {
            keyboard = $(elementReference).getkeyboard();
        }
        return keyboard;
    };

    return {
        attach: function(element, config, inputCallback) {
            var newConfig = clone(VKI_CONFIG);

            config = config || {};

            for (var attr in config) {
                if (config.hasOwnProperty(attr)) {
                    newConfig[attr] = config[attr];
                }
            }

            newConfig.accepted = config.accepted || inputCallback;

            if (config.autoUpdateModel) {
                newConfig.change = config.change || inputCallback;
            }

            if (newConfig.events) {
                var addEventMethod = function(eventName) {
                    return function(e, kb, el) {
                        newConfig.events[eventName](e, $(this).data('keyboard'), this);
                    };
                };

                for (var eventName in newConfig.events) {
                    $(element).on(eventName, addEventMethod(eventName));
                }
            }

            var keyboard = $(element).keyboard(newConfig);

            if (keyboard && newConfig.extensions) {
                for (var extension in newConfig.extensions) {
                    var extConfig = newConfig.extensions[extension];
                    if (extConfig) {
                        keyboard[extension](extConfig);
                    } else {
                        //keyboard[extension]();
                    }
                }
            }
        },
        getKeyboard: function(elementReference) {
            return executeGetKeyboard(elementReference);
        },
        getKeyboardById: function(id) {
            return executeGetKeyboard('#' + id);
        }
    };
}])

.directive('ngVirtualKeyboard', ['ngVirtualKeyboardService', '$timeout',
    function(ngVirtualKeyboardService, $timeout) {
        return {
            restrict: 'A',
            require: '?ngModel',
            scope: {
                config: '=ngVirtualKeyboard'
            },
            link: function(scope, elements, attrs, ngModelCtrl) {
                var element = elements[0];

                if (!ngModelCtrl || !element) {
                    return;
                }

                ngVirtualKeyboardService.attach(element, scope.config, function(e, kb, el) {
                    $timeout(function() {
                        ngModelCtrl.$setViewValue(element.value);
                    });
                });

                scope.$on('$destroy', function() {
                    var keyboard = $(element).getkeyboard();
                    if (keyboard) {
                        keyboard.destroy();
                    }
                });
            }
        };
    }
]);

})(angular);

**** Это работает хорошо, я просто комментирую следующую строку *** // keyboardextension;

но я прав?пожалуйста, ответьте мне !!

...