设置焦点angucomplete-alt

时间:2016-07-04 22:25:13

标签: angularjs angularjs-directive

我正在使用指令angucomplete-alt,我正面临一个问题,一旦页面加载就将注意力集中在输入上,但我不知道该怎么做以及我拥有的解决方案发现看起来非常h​​acky。

示例代码:

<angucomplete-alt id="ex2"
              placeholder="Search people"
              pause="300"
              selected-object="selectedPerson"
              local-data="people"
              local-search="localSearch"
              title-field="firstName,surname"
              description-field="twitter"
              image-field="pic"
              minlength="1"
              input-class="form-control form-control-small"
              match-class="highlight" />

1 个答案:

答案 0 :(得分:1)

好吧,我不知道这个指令,但似乎你不能把注意力放在输入上,而不会有一些黑客。我在他们的github上进行了一些搜索,我在那里找到了相同的issue,并且有一种可能的解决方案可以解决你的问题。

这是一个代码片段:

&#13;
&#13;
var app = angular.module('app', ['angucomplete-alt']);

app.controller('mainCtrl', function($scope, $timeout) {
   $timeout(function() {
     var searchInput = document.getElementById('ex2_value');
     searchInput.focus();
   }, 0);
});
&#13;
<!DOCTYPE html>
<html ng-app="app">

<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.7/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angucomplete-alt/2.4.1/angucomplete-alt.min.js"></script>
</head>

<body ng-controller="mainCtrl">
  <angucomplete-alt id="ex2"
          placeholder="Search people"
          pause="300"
          selected-object="selectedPerson"
          local-data="people"
          local-search="localSearch"
          title-field="firstName,surname"
          description-field="twitter"
          image-field="pic"
          minlength="1"
          input-class="form-control form-control-small"
          match-class="highlight" />
</body>

</html>
&#13;
&#13;
&#13;

我希望它有所帮助。