5

试图了解如何pull-right仅在 angular typeahead 下拉列表中实现该类。

问题:

  • 输入位于窗口的 RHS(这是典型的搜索输入框)
  • 我的结果比我的输入(和包含的 div)更宽
  • 我需要下拉列表的右侧与输入框的右侧对齐,并在左侧延伸过去(下方)输入宽度。
  • (下拉菜单只需要移动,其中的文本对齐方式不会改变,并且应该保持与左对齐。即不是这个问题中的 RTL:RTL for angularjs bootstrap's typeahead

pull-right类应用于包含 div 似乎不会独立于输入影响下拉菜单。
我不知道还能把它放在哪里?

是否有控制下拉 div 对齐方式的 CSS 方法?

修改了以下Plunker中的文档示例

  • pull-right在包含 div 中包含 类
  • 放置在包含 div 以缩小宽度(也许没有必要?)

如果您在 plunker 示例输入框中键入“ ang ”,您将看到结果溢出窗口的右侧。

  <div class='column'>
    <div class='container-fluid pull-right' ng-controller="TypeaheadCtrl">
      <h4>Asynchronous results</h4>
      <pre>Model: {{asyncSelected | json}}</pre>
      <input type="text" ng-model="asyncSelected" placeholder="Locations loaded via $http" typeahead="address for address in getLocation($viewValue)" typeahead-loading="loadingLocations" class="form-control">
      <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
    </div>
  </div>

我查看了以下问题,这些问题似乎对我没有帮助:

4

2 回答 2

5

您需要覆盖由预先输入生成的内联样式.drop-down-menu。大致如下:

<script>
  $('#myInput').on('keypup', function() {
    $(".dropdown-menu").css({ "left": "auto", "right": "10px" });
  });
</script>

普朗克

注意:设置为您与页面/窗口的 RHSright之间的距离input


更新

对于非 jQuery 版本,您必须覆盖using的leftcss 属性.dropdown-menu!important

.dropdown-menu{
  left: auto !important;
  right:10px;
}

更新的 Plunker

于 2015-03-31T22:25:32.790 回答
1

另一种选择是使用typeahead-popup-template-url钩子,对默认模板实现稍作改动。

使用这种方法,您可以使用多个 ui-typeahead 实例来逐一定义所需的布局。

不要忘记根据right您的特定用途调整长度。

(function () {
	'use strict';

  angular.module('myAnswer', ['ui.bootstrap']);
  
})();
<html ng-app="myAnswer">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>
  <div class='container-fluid'>

    <h4>Static arrays</h4>
    <pre>Model: {{selected | json}}</pre>
    
<script type="text/ng-template" id="typeahead-popup-right.html">
  <ul class="dropdown-menu" ng-show="isOpen() && !moveInProgress" ng-style="{top: position().top+'px',left: 'auto', right: '15px'}" role="listbox" aria-hidden="{{!isOpen()}}">
    <li class="uib-typeahead-match" ng-repeat="match in matches track by $index" ng-class="{active: isActive($index) }" ng-mouseenter="selectActive($index)" ng-click="selectMatch($index, $event)" role="option" id="{{::match.id}}">
      <div uib-typeahead-match index="$index" match="match" query="query" template-url="templateUrl"></div>
    </li>
  </ul>
</script>    
    
    
    <input type="text" ng-model="selected" uib-typeahead="state for state in ['Espirito Santo', 'Minhas Gerais', 'Rio de Janeiro', 'São Paulo'] | filter:$viewValue" class="form-control" typeahead-popup-template-url="typeahead-popup-right.html">
    <small class="help-block">Try typing 'Rio' or 'Janeiro'</small>
  </div>
  </body>
</html>

于 2017-05-10T18:41:29.797 回答