Angular 当我切换到另一个页面时,引导选择消失

Angular 当我切换到另一个页面时,引导选择消失,angular,npm,angular-cli,bootstrap-select,Angular,Npm,Angular Cli,Bootstrap Select,我试图将引导选择添加到我的一个项目中,当应用程序加载并且手动点击URL时,它显示良好,但是当我使用路由切换到另一个页面时,选择消失 我的app.module.ts是这样的: @NgModule({ declarations: [ AppComponent, HeaderComponent, SearchComponent, VehiclesComponent, VehicleDetailComponent, VehicleEditCompone

我试图将引导选择添加到我的一个项目中,当应用程序加载并且手动点击URL时,它显示良好,但是当我使用路由切换到另一个页面时,选择消失

我的app.module.ts是这样的:

@NgModule({

declarations: [
    AppComponent,
    HeaderComponent,
    SearchComponent,
    VehiclesComponent,
    VehicleDetailComponent,
    VehicleEditComponent,
    VehicleListComponent,
    VehicleItemComponent,
    AuthComponent,
    SigninComponent,
    SignupComponent,
    MiniSearchComponent,
    AdvancedSearchComponent,
    FooterComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
angular.json文件

"styles": [
          "node_modules/bootstrap/dist/css/bootstrap.min.css",
          "node_modules/bootstrap-select/dist/css/bootstrap-select.min.css",            
          "src/styles.css"
          ],
 "scripts": [
          "node_modules/jquery/dist/jquery.min.js",
          "node_modules/popper.js/dist/umd/popper.min.js",
          "node_modules/bootstrap/dist/js/bootstrap.min.js",
          "node_modules/bootstrap-select/dist/js/bootstrap-select.min.js"
           ]
我正在使用以更改页面,所有其他组件和控件加载良好,除了引导选择


感谢您抽出时间

环顾四周后,我找到了此问题的解决方案:

首先需要使用以下命令为jQuery添加类型包

npm install --save-dev @types/jquery
其次,将以下行添加到tslint.json文件中:

"allowSyntheticDefaultImports": true
第三,将此声明添加到使用select的.ts文件中,它必须在导入之后:

declare var $: any;
第四次执行AfterViewInit并在中添加以下代码:

ngAfterViewInit(): void {
    $('.selectpicker').selectpicker();
}
对于这项工作,您必须已经正确安装了bootstrap4、jQuery、popper和bootstrapselect

我希望这对其他人有帮助