{"action":"created","issue":{"url":"https://api.github.com/repos/angular-ui/ui-select/issues/1285","labels_url":"https://api.github.com/repos/angular-ui/ui-select/issues/1285/labels{/name}","comments_url":"https://api.github.com/repos/angular-ui/ui-select/issues/1285/comments","events_url":"https://api.github.com/repos/angular-ui/ui-select/issues/1285/events","html_url":"https://github.com/angular-ui/ui-select/issues/1285","id":115146231,"number":1285,"title":"ctrl.setItemsFn(data) called when data is undefined","user":{"login":"logannc","id":2867206,"avatar_url":"https://avatars.githubusercontent.com/u/2867206?v=3","gravatar_id":"","url":"https://api.github.com/users/logannc","html_url":"https://github.com/logannc","followers_url":"https://api.github.com/users/logannc/followers","following_url":"https://api.github.com/users/logannc/following{/other_user}","gists_url":"https://api.github.com/users/logannc/gists{/gist_id}","starred_url":"https://api.github.com/users/logannc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logannc/subscriptions","organizations_url":"https://api.github.com/users/logannc/orgs","repos_url":"https://api.github.com/users/logannc/repos","events_url":"https://api.github.com/users/logannc/events{/privacy}","received_events_url":"https://api.github.com/users/logannc/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-04T20:57:36Z","updated_at":"2015-11-04T21:00:17Z","closed_at":null,"body":"For context:\r\n\r\n```javascript\r\n    ctrl.refreshItems = function (data){\r\n      data = data || ctrl.parserResult.source($scope);\r\n      var selectedItems = ctrl.selected;\r\n      //TODO should implement for single mode removeSelected\r\n      if (ctrl.isEmpty() || (angular.isArray(selectedItems) && !selectedItems.length) || !ctrl.removeSelected) {\r\n        ctrl.setItemsFn(data); // <<< line being called\r\n      }else{\r\n        if ( data !== undefined ) {\r\n          var filteredItems = data.filter(function(i) {return selectedItems && selectedItems.indexOf(i) < 0;});\r\n          ctrl.setItemsFn(filteredItems);\r\n        }\r\n      }\r\n      if (ctrl.dropdownPosition === 'auto' || ctrl.dropdownPosition === 'up'){\r\n        $scope.calculateDropdownPos();\r\n      }\r\n    };\r\n```\r\n\r\nI'm using it with `multiple` and `tagging`, just using it to input a list of integers (or whatever). It works fine until you remove all entries (after adding something). That is when this block gets called and sets the items to `undefined` and everything goes to hell. I presume that it is being called because of the middle condition in the `if` statement because it should be a length 0 array at this point. The bug would appear to be that `data` is `undefined` here instead of whatever it expects it should be. I'm not really sure what `data` should be here (though an empty list would seem right :)).\r\n\r\nLet me know if you need anything else on this."},"comment":{"url":"https://api.github.com/repos/angular-ui/ui-select/issues/comments/153863777","html_url":"https://github.com/angular-ui/ui-select/issues/1285#issuecomment-153863777","issue_url":"https://api.github.com/repos/angular-ui/ui-select/issues/1285","id":153863777,"user":{"login":"logannc","id":2867206,"avatar_url":"https://avatars.githubusercontent.com/u/2867206?v=3","gravatar_id":"","url":"https://api.github.com/users/logannc","html_url":"https://github.com/logannc","followers_url":"https://api.github.com/users/logannc/followers","following_url":"https://api.github.com/users/logannc/following{/other_user}","gists_url":"https://api.github.com/users/logannc/gists{/gist_id}","starred_url":"https://api.github.com/users/logannc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logannc/subscriptions","organizations_url":"https://api.github.com/users/logannc/orgs","repos_url":"https://api.github.com/users/logannc/repos","events_url":"https://api.github.com/users/logannc/events{/privacy}","received_events_url":"https://api.github.com/users/logannc/received_events","type":"User","site_admin":false},"created_at":"2015-11-04T21:00:17Z","updated_at":"2015-11-04T21:00:17Z","body":"I've half a mind to just change `data` to `data ? data : [ ]` in that small block. Will that break anything?"}}