angular-selectize icon indicating copy to clipboard operation
angular-selectize copied to clipboard

How do I select an item programatically?

Open pxk5958 opened this issue 8 years ago • 1 comments

I am trying to select an item programatically using selectize.addItem method but it's not working. Here is the essence:

  $scope.myOptions = [{value: '1', text: 'Jordy'}];
  
  $scope.selectize;
   
  $scope.myConfig = {
    create: true,
    // maxItems: 1,
    // required: true,
    onInitialize: function(selectize){
      // receives the selectize object as an argument
      $scope.selectize = selectize;
    }
  }
  
  $scope.selectize.addItem('1');

Am I doing something wrong?

pxk5958 avatar Dec 19 '16 15:12 pxk5958

Found the issue. The options were empty, so addItem wasn't working. I had to manually add the options before addItem.

pxk5958 avatar Dec 19 '16 16:12 pxk5958