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

Angular JS

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

Angular JS

正如HarishR在评论中提到的那样,尚无对此功能的内置支持。

但是我只想尝试一下,结果是这样:http :
//plnkr.co/edit/Qrnat8yTvISuM1qHHDlA?p=preview

它包含许多使它起作用的技巧:

  1. 为了使用.trigger()包含jQuery,可以用本机JS替换,但我很懒。
  2. 使用ng-focus调用.trigger(’input’)触发字体弹出
  3. 使用ng-trim =“ false”禁用输入的值自动修整
  4. 一个自定义的empty-typeahead指令,可与ngModel的控制器进行交互,以应用secretEmptyKey逻辑来绕过typeahead-min-length检查:
        .directive('emptyTypeahead', function () {      return {        require: 'ngModel',        link: function (scope, element, attrs, modelCtrl) {          // this parser run before typeahead's parser          modelCtrl.$parsers.unshift(function (inputValue) { var value = (inputValue ? inputValue : secretEmptyKey); // replace empty string with secretEmptyKey to bypass typeahead-min-length check modelCtrl.$viewValue = value; // this $viewValue must match the inputValue pass to typehead directive return value;          });          // this parser run after typeahead's parser          modelCtrl.$parsers.push(function (inputValue) { return inputValue === secretEmptyKey ? '' : inputValue; // set the secretEmptyKey back to empty string          });        }      }    })
  1. 一个自定义过滤器比较器函数,当一个参数为secretEmptyKey时始终返回true(显示所有结果):

    $scope.stateComparator = function (state, viewValue) {

    return viewValue === secretEmptyKey || (‘’+state).toLowerCase().indexOf((‘’+viewValue).toLowerCase()) > -1;
    };

  2. 删除limitTo过滤器以显示所有结果

  3. 如果内容太长,则设置max-height和溢出CSS属性以显示滚动条

做完了!



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

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

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