栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

AngularJS Chrome自动完成难题

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

AngularJS Chrome自动完成难题

从评论中添加的链接:Github
Issue的

// Due to browsers issue, it's impossible to detect without a timeout any changes of autofilled inputs// https://github.com/angular/angular.js/issues/1460// https://github.com/angular/angular.js/issues/1460#issuecomment-28662156// Could break future Angular releases (if use `compile()` instead of `link())// TODO support selectangular.module("app").config(["$provide", function($provide) {    var inputDecoration = ["$delegate", "inputsWatcher", function($delegate, inputsWatcher) {        var directive = $delegate[0];        var link = directive.link;        function linkDecoration(scope, element, attrs, ngModel){ var handler; // By default model.$viewValue is equals to undefined if(attrs.type == "checkbox"){     inputsWatcher.registerInput(handler = function(){         var value = element[0].checked;         // By default element is not checked         if (value && ngModel.$viewValue !== value) {  ngModel.$setViewValue(value);         }     }); }else if(attrs.type == "radio"){     inputsWatcher.registerInput(handler = function(){         var value = attrs.value;         // By default element is not checked         if (element[0].checked && ngModel.$viewValue !== value) {  ngModel.$setViewValue(value);         }     }); }else{     inputsWatcher.registerInput(handler = function(){         var value = element.val();         // By default value is an empty string         if ((ngModel.$viewValue !== undefined || value !== "") && ngModel.$viewValue !== value) {  ngModel.$setViewValue(value);         }     }); } scope.$on("$destroy", function(){     inputsWatcher.unregisterInput(handler); }); // Exec original `link()` link.apply(this, [].slice.call(arguments, 0));        }        // Decorate `link()` don't work for `inputDirective` (why?)                // So use `compile()` instead        directive.compile = function compile(element, attrs, transclude){ return linkDecoration;        };        delete directive.link;        return $delegate;    }];    $provide.decorator("inputDirective", inputDecoration);    $provide.decorator("textareaDirective", inputDecoration);    //TODO decorate selectDirective (see binding "change" for `Single()` and `Multiple()`)}]).factory("inputsWatcher", ["$interval", "$rootScope", function($interval, $rootScope){    var INTERVAL_MS = 500;    var promise;    var handlers = [];    function execHandlers(){        for(var i = 0, l = handlers.length; i < l; i++){ handlers[i]();        }    }    return {        registerInput: function registerInput(handler){ if(handlers.push(handler) == 1){     promise = $interval(execHandlers, INTERVAL_MS); }        },        unregisterInput: function unregisterInput(handler){ handlers.splice(handlers.indexOf(handler), 1); if(handlers.length == 0){     $interval.cancel(promise); }        }    }}]);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/636228.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号