core114
core114

Reputation: 5335

Bootsrap Buttons with dropdowns, convert to ng-bootstrap Buttons with dropdowns,

Im beginner to Angular,I want to know how to correctly create this code for the ng-bootsrap ,I can do it using bootstrap-4 but I don't know Angular, Im follow this Ng-bootstrap drop down ,but not work please help me , Thanks

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">

<div class="row">
  <div class="col-lg-6">
    <div class="input-group">
      <div class="input-group-btn">
        <button type="button" class="btn btn-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
         Currency
        </button>
        <div class="dropdown-menu">
          <a class="dropdown-item" href="#">USD</a>
          <a class="dropdown-item" href="#">AUS</a>
       
        </div>
      </div>
      <input type="text" class="form-control" aria-label="Text input with dropdown button">
    </div>
  </div>
 
</div>

Upvotes: 0

Views: 1135

Answers (2)

core114
core114

Reputation: 5335

I found the solution ,Now its work for me , Recommend for the ng-bootstrap team

GitHub

Live sample

<div class="input-group">
  <div class="input-group-btn">
    <div class="btn-group" ngbDropdown role="group" aria-label="Button group with nested dropdown">
      <button class="btn btn-secondary" ngbDropdownToggle>Action</button>
      <div class="dropdown-menu" ngbDropdownMenu>
        <button class="dropdown-item">One</button>
        <button class="dropdown-item">Two</button>
        <button class="dropdown-item">Four!</button>
      </div>
    </div>
  </div>
  <input type="text" class="form-control" aria-label="Text input with dropdown button">
</div>

Upvotes: 0

Quan Vo
Quan Vo

Reputation: 1336

If you use ng-bootstrap with Angular 5, you should install bootstrap via npm, like here. This is an example about dropdown menu. I'm using @ng-bootstrap/[email protected] and I modified your code, worked fine:

<div ngbDropdown>
    <button type="button" class="btn btn-secondary" ngbDropdownToggle>
      Currency
    </button>
    <div ngbDropdownMenu>
      <a class="dropdown-item" href="#">USD</a>
      <a class="dropdown-item" href="#">AUS</a>
    </div>
</div>

Define a variable named items in your .ts file: items = ['A','B','C'], then replace your dropdown by:

<a class="dropdown-item" href="#" *ngFor="let item of items">{{item}}</a>

Upvotes: 0

Related Questions