在我的 Laravel-12 中,我使用的是 AdminLTE 主题。
angular.json
"scripts": [
"node_modules/admin-lte/plugins/jquery/jquery.min.js",
"node_modules/admin-lte/plugins/jquery-ui/jquery-ui.min.js",
"node_modules/admin-lte/plugins/select2/js/select2.full.min.js",
"node_modules/admin-lte/plugins/bootstrap/js/bootstrap.bundle.min.js",
"node_modules/admin-lte/plugins/chart.js/Chart.min.js",
"node_modules/admin-lte/plugins/sparklines/sparkline.js",
"node_modules/admin-lte/plugins/jqvmap/jquery.vmap.min.js",
"node_modules/admin-lte/plugins/jqvmap/maps/jquery.vmap.usa.js",
"node_modules/admin-lte/plugins/jquery-knob/jquery.knob.min.js",
"node_modules/admin-lte/plugins/moment/moment.min.js",
"node_modules/admin-lte/plugins/jquery-mousewheel/jquery.mousewheel.js",
"node_modules/admin-lte/plugins/raphael/raphael.min.js",
"node_modules/admin-lte/plugins/jquery-mapael/jquery.mapael.min.js",
"node_modules/admin-lte/plugins/jquery-mapael/maps/usa_states.min.js",
"node_modules/admin-lte/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js",
"node_modules/admin-lte/plugins/summernote/summernote-bs4.min.js",
"node_modules/admin-lte/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js",
"node_modules/datatables.net/js/jquery.dataTables.js",
"node_modules/admin-lte/dist/js/adminlte.min.js"
],
组件:
ngOnInit(): void {
this.buildForm();
this.maritalStatusData = MARITAL_STATUS_DATA;
this.genderData = GENDER_DATA;
//Initialize Select2 Elements
$('.select2bs4').select2({
theme: 'bootstrap4'
})
}
HTML:
<div class="form-group">
<label for="name">Marital Status:<span style="color:red;">*</span></label>
<select id="marital_status" class="form-control select2bs4" formControlName="marital_status" placeholder="Marital Status" style="width: 100%;">
<option value="">Select one</option>
<option *ngFor="let marital of maritalStatusData" [value]="marital.key">{{ marital.value }}</option>
</select>
</div>
但是得到这个错误:
<块引用>core.js:6456 ERROR TypeError: $(...).select2 不是函数
stackoverflow 上的其他解决方案无法解决我的问题。
我该如何解决这个问题?
谢谢