Set already selected values in angular 1 dynamic select dropdown while ng-click throghing error - TypeError: selectize.setValue is not a function

Viewed 172

I have a select dropdown with option values. And this select dropdown is dynamically displaying. I want to show the selected value of each dropdown while selecting/clicking each select dropdown.

My blade file is

<div class="accordion__item"  data-ng-repeat="pref_favs in coachProfileCtrl.coach.child_pref_categories" id="@{{pref_favs.pref_categories.id}}">
    <div data-ng-click="coachProfileCtrl.loadprofilecategoryactions($event);" data-id="@{{pref_favs.pref_categories.id}}" class="accordion__header">@{{pref_favs.pref_categories.title}}</div>
        <div class="accordion__body_new">
            <p >
                <select targetfield="title" general-selectize-directive id="category_videos_selectize_@{{pref_favs.pref_categories.id}}" service="category_videos" name="category_videos" multiple="multiple" style="display: block;" data-ng-model="coachProfileCtrl.coach.category_videos">
                    <option value="" disabled selected>{{ trans('frontend::messages.select_action') }}</option>
                </select>
                <div class="save-button">
                    <button type="button" class="btn btn-warning" data-ng-click="coachProfileCtrl.saveprofilecategoryactions();">Save Actions</button>
                </div>
            </p>
        </div>
     </div>
</div>

And my click action is like

this.coach.category_id = $($event.target).attr('data-id');
angular.forEach($scope.categories_actions_lists, function(value, key) {
    if(key == $($event.target).attr('data-id') ) {
        var $select = $("#category_videos_selectize_" + key ).selectize();
        var selectize = $select[0].selectize;
        selectize.setValue(value);
    }
});

and am getting errors like

TypeError: selectize.setValue is not a function

Any help!

1 Answers

Yes, finally I got the answer!

if(key == $($event.target).attr('data-id') ) {
   $("#category_videos_selectize_" + key)[0].selectize.setValue(value);
}
Related