【问题标题】:Bootstrap dropdown using ngx-bootstrap使用 ngx-bootstrap 的引导下拉菜单
【发布时间】:2018-04-18 10:46:58
【问题描述】:

我会使用以下命令在 angular2 中安装 ngx-bootstrap npm install ngx-bootstrap bootstrap --save

包含在 angular-cli.json 中的以下行

 "../node_modules/bootstrap/dist/css/bootstrap.min.css".

在 app.component.html 中添加以下行

  <div  class="dropdown">
     <a class="pull-right text-center btn btn-setting dropdown-toggle"  data-toggle="dropdown" aria-haspopup="true" aria- expanded="true"><i class="fa fa-cog"></i></a>
     <ul class="dropdown-menu" role="menu" aria-labelledby="menu1">
        <li role="presentation">  <a role="menuitem" tabindex="-1" href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-cog"></i>Settings</a></li>
     </ul>                                      
  </div>

以上代码不适用于引导下拉菜单 但是下拉菜单不起作用。请帮助我。

我的 package.json 是

{
 "name": "offline-new",
 "version": "0.0.0",
 "license": "MIT",
 "angular-cli": {},
 "scripts": {
"ng": "ng",
"start": "ng serve",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
 },
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"@types/hammerjs": "^2.0.35",
"angular2-drag-scroll": "^1.4.4",
"angular2-fontawesome": "^0.9.3",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"jsstore": "^1.2.6",
"ng2-materialize": "^1.3.2",
"ngx-bootstrap": "^2.0.0-beta.8",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
 },
 "devDependencies": {
"@angular/cli": "^1.5.0",
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/node": "^6.0.42",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "~4.0.13",
"ts-node": "1.2.1",
"tslint": "^4.3.0",
"typescript": "~2.0.3"
}
}

谢谢

【问题讨论】:

  • 您应该向 sn-ps 提供您拥有的代码,并说明您希望您的代码做什么

标签: angular typescript ngx-bootstrap


【解决方案1】:

你是否在你的 app.module.ts 中添加了这个??

import { BsDropdownModule } from 'ngx-bootstrap/dropdown'
@NgModule({
  imports: [BsDropdownModule.forRoot(),...]
})
export class AppModule(){}

还将您的 app.component.html 更新为

<div  class="dropdown" dropdown>
    <a dropdownToggle class="pull-right text-center btn btn-setting dropdown-toggle"  data-toggle="dropdown" aria-haspopup="true" aria- expanded="true"><i class="fa fa-cog"></i></a>
    <ul *dropdownMenu class="dropdown-menu" role="menu" aria-labelledby="menu1">
        <li role="presentation">  <a role="menuitem" tabindex="-1" href="#" data-toggle="modal" data-target="#myModal"><i class="fa fa-cog"></i>Settings</a></li>
    </ul>
</div>

【讨论】:

  • 我添加了这个。但是我得到了 ./node_modules/ngx-bootstrap/dropdown/bs-dropdown.directive.js 247:16-25 "export 'Renderer2' was not found in '@angular/ core' 警告错误和“无法解析 BsDropdownContainerComponent 的所有参数:([object Object], [object Obje…,”控制台错误
  • 你能给我们看看你的 package.json。也许您使用的版本不支持 angular v4 及更高版本,或者尝试将您的 ngx-bootstrap 版本更改为 ^2.0.0-beta.8
  • 我认为"ngx-bootstrap": "^2.0.0-beta.8" 不支持 Angular 2.x 你试过检查向后兼容性吗?还是您尝试将 Angular 更新到最新版本?并确保在这样做之前备份您的旧代码。
  • 谢谢。我更新了 angular5。现在它工作正常。
  • 但更新后,使用 route.navigate 的路线导航不起作用。
猜你喜欢
  • 2023-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 2012-07-05
  • 2015-08-08
  • 2019-07-16
  • 1970-01-01
相关资源
最近更新 更多