【问题标题】:Angular 2 : ng bootstrap drop down not working for meAngular 2:ng bootstrap drop down 不适合我
【发布时间】:2017-11-01 02:46:14
【问题描述】:

我一直在尝试使用 plunker http://plnkr.co/edit/?p=preview 实现 ng-bootstrap 下拉。

它不工作,我找不到问题

.

system.config.js 代码下方,

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
  System.config({
    paths: {
      // paths serve as alias
      'npm:': 'node_modules/'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@ng-bootstrap/ng-bootstrap': 'node_modules/@ng-bootstrap/ng-bootstrap/bundles/ng-bootstrap.js',
      // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.js',
        defaultExtension: 'js'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      
    }
  });
})(this);

app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { NgbdDropdownConfig } from 'app/dropdown-config';
import { AppComponent }  from './app.component';

@NgModule({
  imports:      [ BrowserModule, ],
  declarations: [ AppComponent,NgbdDropdownConfig ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

app.component.ts 代码

import { Component } from '@angular/core';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { NgbdDropdownConfig } from 'app/dropdown-config';
@Component({
  selector: 'my-app',
  template: ` <div class="container-fluid">
    
    <ngbd-dropdown-config></ngbd-dropdown-config>
  </div>`,
})
export class AppComponent  {  }

dropdown-config.ts 代码

import {Component} from '@angular/core';
import {NgbDropdownConfig} from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'ngbd-dropdown-config',
  templateUrl: 'app/dropdown-config.html',
  providers: [NgbDropdownConfig] // add NgbDropdownConfig to the component providers
})
export class NgbdDropdownConfig {
  constructor(config: NgbDropdownConfig) {
    // customize default values of dropdowns used by this component tree
    config.up = true;
    config.autoClose = false;
  }
}

下拉配置.html

<p>This dropdown uses customized default values.</p>

<div ngbDropdown>
  <button class="btn btn-outline-primary" id="dropdownMenu3" ngbDropdownToggle>Toggle</button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenu3">
    <button class="dropdown-item">Action - 1</button>
    <button class="dropdown-item">Another Action</button>
    <button class="dropdown-item">Something else is here</button>
  </div>
</div>

由于没有错误信息,我无法找到问题。任何人都可以找出问题所在。谢谢。

【问题讨论】:

  • 请正确链接到 plunker
  • 究竟是什么问题?
  • 对不起,这是链接,在最后一个中,我实现了“下拉菜单的全局配置”ng-bootstrap.github.io/#/components/dropdown
  • 切换的下拉不能同时工作,它没有显示任何错误。
  • 您提供了工作示例的链接!要解决您的问题,我们应该从遇到此问题的 plunker 开始。比先做工作重现你的问题然后解决它更有效

标签: javascript angular ng2-bootstrap


【解决方案1】:

使用最新版本(1.0.0-alpha.18)它也不适用于我。降级到以前的版本:

npm i @ng-bootstrap/ng-bootstrap@1.0.0-alpha.17 --save

应该没问题。

【讨论】:

    【解决方案2】:

    @Manjula D 只需在 dropdown-config.html 中进行以下更改

    <div ngbDropdown>
      <button class="btn btn-outline-primary" id="dropdownMenu3" ngbDropdownToggle>Toggle</button>
      <div class="dropdown-menu" aria-labelledby="dropdownMenu3" ngbDropdownMenu>
        <button class="dropdown-item">Action - 1</button>
        <button class="dropdown-item">Another Action</button>
        <button class="dropdown-item">Something else is here</button>
      </div>
    </div>
    

    ngbDropdownMenu 是添加到“下拉菜单”div 中的属性。

    【讨论】:

      【解决方案3】:

      我也遇到过类似的问题:

      我跑了

      npm install --save @ng-bootstrap/ng-bootstrap
      
      npm install --save bootstrap@4.0.0-beta.2
      

      模板/html 在这里提供: https://ng-bootstrap.github.io/#/components/dropdown/examples

      在styles.css中:

      @import "~bootstrap/dist/css/bootstrap.css";
      

      到现在还是不行,所以我重新跑了

      npm install
      

      一切顺利。

      【讨论】:

        猜你喜欢
        • 2019-07-24
        • 2017-01-01
        • 2018-03-26
        • 2019-03-21
        • 2013-03-01
        • 1970-01-01
        • 2012-03-04
        • 2023-03-17
        • 1970-01-01
        相关资源
        最近更新 更多