Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从ui选择更改事件中获取搜索值_Javascript_Angularjs_Ui Select - Fatal编程技术网

Javascript 如何从ui选择更改事件中获取搜索值

Javascript 如何从ui选择更改事件中获取搜索值,javascript,angularjs,ui-select,Javascript,Angularjs,Ui Select,我试图捕获并调用ui-select元素的搜索值上的函数。具体来说,我希望在每次击键时获得ui select match元素的值 在正常的输入元素中,我可以执行以下操作: // controller class selectController { constructor($scope) { this.$scope = $scope; this.query = ''; this.numChars = 0; countChars(q) { this.quer

我试图捕获并调用
ui-select
元素的搜索值上的函数。具体来说,我希望在每次击键时获得
ui select match
元素的值

在正常的
输入
元素中,我可以执行以下操作:

// controller
class selectController {
  constructor($scope) {
    this.$scope = $scope;
    this.query = '';
    this.numChars = 0;

  countChars(q) {
    this.query = q;
    this.numChars = q.length;
  }
}

// template
<input ng-model="q" ng-change="ctrl.countChars(q)">...</input>

当用户键入搜索查询并在控制器中对其执行操作时,如何捕获该查询?

我可以通过向
用户界面选择添加
刷新
刷新延迟
来解决该问题

// controller
class selectController {
  constructor($scope) {
    this.$scope = $scope;
    this.query = '';
    this.numChars = 0;
    this.advisor = {};
    this.advisors = [
      { name: 'Cheryl Aubuchon' },
      { name: 'Jerome Brown' },
      { name: 'John Doe' },
      { name: 'Jane Doe' },
      { name: 'Deborah Grimm' },
      { name: 'Tommy Harris' },
      { name: 'Sally Smith' },
      { name: 'Harry Velez' },
      { name: 'Chelsie Williamson' }
    ];
  }

  countChars(q) {
    this.query = q;
    this.numChars = q.length;
  }
}

// template
<p ng-bind="ctrl.query"></p>

<ui-select ng-model="ctrl.advisor.selected">
    <ui-select-match allow-clear placeholder="Select an Advisor" class="ui-select-match">
        <span ng-bind="$select.selected.name"></span>
    </ui-select-match>
    <ui-select-choices class="ui-select-choices" repeat="advisor in (ctrl.advisors | filter: $select.search)" refresh="ctrl.countChars($select.search)" refresh-delay="0">
        <span ng-bind="advisor.name"></span>
    </ui-select-choices>
</ui-select>
//控制器
类选择器控制器{
构造函数($scope){
这个.$scope=$scope;
this.query='';
此值为0.numChars=0;
this.advisor={};
这是我的建议=[
{name:'Cheryl Aubuchon'},
{姓名:'杰罗姆·布朗'},
{姓名:'约翰·多伊'},
{姓名:'无名氏'},
{name:'Deborah Grimm'},
{姓名:'汤米·哈里斯'},
{姓名:'萨利·史密斯'},
{名字:'哈利·韦雷斯'},
{姓名:'Chelsie Williamson'}
];
}
countChars(q){
this.query=q;
this.numChars=q.length;
}
}
//模板


angular和ui选择的版本?
// controller
class selectController {
  constructor($scope) {
    this.$scope = $scope;
    this.query = '';
    this.numChars = 0;
    this.advisor = {};
    this.advisors = [
      { name: 'Cheryl Aubuchon' },
      { name: 'Jerome Brown' },
      { name: 'John Doe' },
      { name: 'Jane Doe' },
      { name: 'Deborah Grimm' },
      { name: 'Tommy Harris' },
      { name: 'Sally Smith' },
      { name: 'Harry Velez' },
      { name: 'Chelsie Williamson' }
    ];
  }

  countChars(q) {
    this.query = q;
    this.numChars = q.length;
  }
}

// template
<p ng-bind="ctrl.query"></p>

<ui-select ng-model="ctrl.advisor.selected">
    <ui-select-match allow-clear placeholder="Select an Advisor" class="ui-select-match">
        <span ng-bind="$select.selected.name"></span>
    </ui-select-match>
    <ui-select-choices class="ui-select-choices" repeat="advisor in (ctrl.advisors | filter: $select.search)" refresh="ctrl.countChars($select.search)" refresh-delay="0">
        <span ng-bind="advisor.name"></span>
    </ui-select-choices>
</ui-select>