我试图在选项中使用添加按钮,但问题是ng-click触发但未选中该选项.
<ui-select ng-model="datactrl.newservice.selected" theme="selectize" ng-disabled="disabled" style="width: 100%;"> <ui-select-match placeholder="..."> <span ng-bind-html="$select.selected.name"></span> </ui-select-match> <ui-select-choices repeat="service in data.base_services | filter: $select.search"> <span ng-bind-html="service.name | highlight: $select.search"></span> <!-- HERE NOT --> <a href="" class="pull-right" ng-click="setnewservice()"> <i class="glyphicon glyphicon-plus-sign"></i> </a> <!-- ### --> </ui-select-choices> </ui-select> <!-- here obvIoUsly works --> <a href="" class="pull-right" ng-click="setnewservice()"> <i class="glyphicon glyphicon-plus-sign"></i> </a>
我可以向函数发送一些参数并处理这种情况,甚至选择该项目索引的点击链接,以便模型采用正确的值,
或者像上面的工作样品一样把它带到外面……
但是我怎样才能正确处理这个,停止事件,选择选项而不发送对象或它的一些属性,然后做其余的事情?
$scope.setnewservice = function ($event) { $event.stopPropagation(); // ?? }
在ui-select上使用ng-change而不是单击ui-select-choices.改变这个:
ng-click="setnewservice()
至:
ui-select ng-model="datactrl.newservice.selected" theme="selectize" ng-disabled="disabled" style="width: 100%;" ng-change="setnewservice()>