我正在使用 Angular UI 团队的官方 Bootstrap 实现,所以它不是 angular-strap 而是 angular-bootstrap。我有一个工作正常的预输入,但它不尊重占位符文本。原因是我的结果文本中有一个空格。
这是一个例子......
<input type="text" id="clientSelected" ng-model="clientSelected" typeahead="client as (client.firstName + ' ' + client.lastName) for client in clients | filter:$viewValue" placeholder="Just start typing...">
客户名称被列为:John Doe、Jane Doe 等。所以没有什么特别之处。这是负责填充客户端的控制器部分。
$scope.$apply(function() {
// Result has come back from the server
$scope.clients = result;
// Doesn't fix the problem
$scope.clientSelected = '';
// Hack to fix typeahead
angular.element('#clientSelected').val('');
});
所以,通过这个实现,我的输入总是有一个" "
,所以占位符没有显示,初始值为ng-model="clientSelected"
a " "
。预输入之间的空格(client.firstName + ' ' + client.lastName)
是原因。
拥有 jQuery 背景后,我立即想使用上面的 hack 代码将其强制为零字符。显然,这是不对的,我错过了一些基本的东西。
那么,我怎样才能告诉它input
是零个字符还是完全解决问题呢?