如何修复以下错误? TypeError:f [s]不是函数

时间:2018-11-29 13:13:54

标签: angularjs angularjs-directive angularjs-scope

//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-虚拟键盘              *基于Mottie / Keyboard的AngularJs虚拟键盘接口              * @版本v0.3.3              * @作者antonio-spinelli              * @link https://github.com/antonio-spinelli/ng-virtual-keyboard              * @许可证麻省理工学院              * /             (函数(角度){

        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 :(得分:0)

async

****它运作良好,我只是在以下一行中发表评论*** // keyboardextension;

但是我说的对吗?请回答我!