尝试了解如何仅在angular typeahead下拉列表中实现pull-right
类。
问题:
将pull-right
类应用于包含div似乎不会独立于输入而影响下拉列表
我不知道还能把它放在哪里呢?
是否有一种控制下拉列表对齐的CSS方法?
修改了以下documentation example中的Plunker:
pull-right
类
如果您在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>
我看过以下问题,似乎对我没有帮助:
答案 0 :(得分:3)
您需要覆盖由typeahead为.drop-down-menu
生成的内联样式。类似的东西:
<script>
$('#myInput').on('keypup', function() {
$(".dropdown-menu").css({ "left": "auto", "right": "10px" });
});
</script>
注意:将right
设置为input
与页面/窗口的RHS之间的距离
<小时/> 的更新强>
对于非jQuery版本,您必须使用left
.dropdown-menu
的{{1}} css属性
!important
<强> Updated Plunker 强>
答案 1 :(得分:0)
另一种选择是使用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>