Angular js使用ng-change将值从选择菜单传递给控制器

问题描述 投票:0回答:1

我想通过每次我从ui-select到控制器选择一个项目我尝试使用ng-update和ng更改但它似乎不起作用。任何的想法?为什么代码在下面。谢谢。我只想在从ui选择中选择一个项目时触发一个功能。

controller

 $scope.update = function () {
     alert("triggered")
 }

view

<ui-select ng-change="update()" multiple="multiple" tagging="tagging" tagging-label="(custom 'new' label)" ng-model="main.record.skills" theme="bootstrap" sortable="true" style="width: 300px;" title="">
  <ui-select-match class="ui-select-match" placeholder="Select skills">{$ $select.selected.name $}{$ $item.name | limitTo:70 $} {$ $item.name.length > 70 ? "..." : "" $}</ui-select-match >
  <ui-select-choices ng-change="main.update()" refresh="main.read_skills($select.search)" repeat="skill in main.skills | filter:$select.search track by $index">
    <div ng-bind-html="skill.name | highlight: $select.search"></div>
    {$ name $}
  </ui-select-choices>
</ui-select>
javascript angularjs drop-down-menu ui-select
1个回答
1
投票

将on-select =“onSelected($ item)”添加到你的ui-select和控制器中:

$scope.onSelected = function (selectedItem) {
  //do selectedItem.PropertyName like 
//selectedItem.Name or selectedItem.Key 
//whatever property your list has.
}
© www.soinside.com 2019 - 2024. All rights reserved.