angular-selectize
angular-selectize copied to clipboard
How do I select an item programatically?
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?
Found the issue. The options were empty, so addItem wasn't working. I had to manually add the options before addItem.