问题
I've implemented select box using bootstrap-select in angular 5. I've used latest version of Bootstrap select to make it work angular 5. But it throws below error.
bootstrap-select.js:1904 Uncaught TypeError: Cannot set property '_menu' of undefined
<form>
<select class="selectpicker" data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
</form>
View Plunkr
回答1:
Bootstrap-select v1.13.0-dev is compatible with Boostrap 4. You can find Compatible bootstrap-select files here Boostrap-select
Isue is that i am not loading required jquery and popper.min.js files into project directory. Also use non minified version of bootstrap select from repository code. I've solved this issue by adding above files.
回答2:
https://getbootstrap.com/docs/4.0/components/input-group/#custom-select
Your issue is that you aren't using the select dropdown properly according to Bootstrap 4. You can't upgrade from Bootstrap 3 to Bootstrap 4 without updating your code to use the new methodologies, unfortunately.
<select class="custom-select" data-live-search="true">
<option>Mustard</option>
<option>Ketchup</option>
<option>Relish</option>
</select>
回答3:
I suspect that the plugin you're using isn't compatible with Bootstrap 4. The documentation and examples all use Bootstrap 3.
https://silviomoreto.github.io/bootstrap-select/
回答4:
It works in bootstrap-select v1.13.11 with bootsrrap v4.3.1 and jQuery v3.4.1.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap-select@1.13.11/dist/js/bootstrap-select.min.js"></script>
I found out the problem was with bootstrap.bundle.min.js, please use the latest version instead.
来源:https://stackoverflow.com/questions/49014163/bootstrap-select-error-cannot-set-property-menu-of-undefined