Проблемы с выпадающим списком в Angularjs

Резюме:

Я использую директиву angularjs-dropdown-multiselect.

Ссылка: AngularJS Dropdown Multiselect

Проблемы, стоящие перед:

Проблема 1: я хочу использовать onItemSelect & onItemDeselect события, когда пользователь выбирает или отменяет выбор параметров из раскрывающегося списка.

Я настраиваю их успешно, но проблема в том, что без выбора какой-либо опции также эти события выполняются часто.

HTML

<div ng-dropdown-multiselect="" options="listClientCompany" selected-model="selectedClients" extra-settings="clientSelectionSettings" translation-texts="translations" events="onItemSelect(selectedClients);onItemDeSelect(selectedClients)"></div>

Контроллер:

$scope.selectedClients = []; 
$scope.clientSelectionSettings = {idProp: '_id',displayProp:'name',externalIdProp : "_id",enableSearch:false,scrollableHeight: '200px',scrollable:true};   
$scope.translations = {buttonDefaultText: 'Select'};

$scope.onItemSelect = function(item) {
  console.log(item); // execute multiple times on page load also without selecting any option from the dropdown.
}

Скриншот:

Я также попробовал решение, определенное здесь:

https://github.com/dotansimha/angularjs-dropdown-multiselect/issues/39. Но не добился успеха.

Проблема 2: Когда я удалялся $scope.selectedClients = []; с контроллера это дает мне эту ошибку в консоли.

Error: [$interpolate:interr] Can't interpolate: {{getButtonText()}} 
TypeError: Cannot read property 'length' of undefined
http://errors.angularjs.org/1.2.19/$interpolate/interr?p0=%7B%7BgetButtonTe…%A0&p1=TypeError%3A%20Cannot%20read%20property%20'length'%20of%20undefined
    at http://0.0.0.0:9000/bower_components/angular/angular.js:78:12
    at Object.$interpolate.fn (http://0.0.0.0:9000/bower_components/angular/angular.js:8756:26)
    at Scope.$digest (http://0.0.0.0:9000/bower_components/angular/angular.js:12426:40)
    at Scope.$apply (http://0.0.0.0:9000/bower_components/angular/angular.js:12699:24)
    at done (http://0.0.0.0:9000/bower_components/angular/angular.js:8287:45)
    at completeRequest (http://0.0.0.0:9000/bower_components/angular/angular.js:8499:7)
    at XMLHttpRequest.xhr.onreadystatechange (http://0.0.0.0:9000/bower_components/angular/angular.js:8438:11) angular.js:9959

Я также попробовал решение, определенное здесь:

https://github.com/dotansimha/angularjs-dropdown-multiselect/issues/22 но безуспешно.

Любая немедленная помощь по обоим вопросам будет весьма заметна. Спасибо

1 ответ

Вы всегда отправляете массив в функцию, которую вы должны сделать

$scope.selectedClients = []; 
$scope.selectedClient = {};
$scope.clientSelectionSettings = {idProp: '_id',displayProp:'name',externalIdProp : "_id",enableSearch:false,scrollableHeight: '200px',scrollable:true};   
$scope.translations = {buttonDefaultText: 'Select'};

$scope.onItemSelect = function(item) {
  //then you can push your object to the array
  console.log(item); // execute multiple times on page load also without selecting any option from the dropdown.
}

а также

<div ng-dropdown-multiselect="" options="listClientCompany" selected-model="selectedClient" extra-settings="clientSelectionSettings" translation-texts="translations" events="onItemSelect(selectedClient);onItemDeSelect(selectedClient)"></div>
Другие вопросы по тегам