【问题标题】:Poplulating list of user in a textbox like whatsapp in angularjs在 angularjs 中的 whatsapp 等文本框中填充用户列表
【发布时间】:2016-11-15 11:13:33
【问题描述】:

当用户在文本框中按下 @ 按钮时,我想填充用户列表,例如 angularjs 中的 whatsapp“组”。 html 是
<input class="nostyle search-filter" ng-model="searchUsers" type="text" placeholder="Search" />

控制器'$scope.allGroupMembers' 是一个数组,其中包含该组的所有用户。 提前致谢

【问题讨论】:

  • 请向我们展示您的尝试。你看过 JQuery 自动完成吗?
  • 澄清你的问题,你的 allgroupMembers 数组包含什么意味着它包含成员名称或对象。请清除它。
  • 它包含对象,其中名称是显示给用户的属性,并且该名称与输入框的文本连接。

标签: javascript angularjs


【解决方案1】:

用户输入“@”时使用$watch触发showList

HTML

<input class="nostyle search-filter" ng-model="searchUsers" type="text" placeholder="Search" />

  <div ng-show="showList">
    <div ng-repeat="user in allGroupMembers">
      {{user.name}}
    </div>
  </div>

JS

$scope.showList=false;


$scope.$watch('searchUsers'. function(newValue, oldValue){
   if(newValue[newValue.length]==='@'){

       $scope.showList=true; //Function to show list of user from array.
   }

});

【讨论】:

    猜你喜欢
    • 2013-11-01
    • 2015-04-03
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多