【发布时间】:2020-11-05 16:48:38
【问题描述】:
我正在尝试在我的 Angular 9 项目中让可搜索的选择框与引导程序一起使用。为此我使用bootstrap select.
以下是我的实现方式。
在我的模板中:-
<div class="form-group row">
<label for="txnSubCategory" class="col-sm-6 col-md-4 col-form-label">Transaction Sub Category</label>
<div class="col-sm-6 col-md-8">
<select #selectTxnSubCategory class="form-control selectpicker" data-live-search="true" id="txnSubCategory" data-width="100%"
formControlName="txnSubCategory">
<option data-tokens="ABCD" value="Yes" selected>ABCD</option>
<option data-tokens="PQRS" value="No">PQRS</option>
<option data-tokens="LMNO" value="No">LMNO</option>
</select>
</div>
</div>
在组件中:-
@ViewChild('selectTxnSubCategory') selectTxnSubCategory: ElementRef;
ngAfterViewInit() {
this.selectTxnSubCategory.nativeElement.selectpicker('refresh');
}
在我的 json 包中,我确保将 bootstrap-select 放在 jquery 之后。与 angular.json 文件相同。这样引导选择不会被 jquery 覆盖。
但是,当我运行程序时,我在视图中看不到我的选择下拉菜单。我在控制台中收到以下错误。
core.js:6241 ERROR TypeError: this.selectTxnSubCategory.nativeElement.selectpicker is not a function
at BasicInfoComponent.ngAfterViewInit (basic-info.component.ts:33)
at callHook (core.js:4726)
at callHooks (core.js:4690)
at executeInitAndCheckHooks (core.js:4630)
at refreshView (core.js:12088)
at refreshEmbeddedViews (core.js:13404)
at refreshView (core.js:12035)
at refreshComponent (core.js:13458)
at refreshChildComponents (core.js:11729)
at refreshView (core.js:12064)
我该如何解决这个问题?
【问题讨论】:
-
@NitinLawande 我也检查过。还是同样的问题。
标签: angular bootstrap-4 angular9 bootstrap-select bootstrap-selectpicker