如何在ng-bootstrap中获取Dropdown的值?

时间:2017-09-20 09:30:53

标签: angular ng-bootstrap

我正在使用ng-bootstrap,我希望在选择时获得下拉值。

library(gplots)
library(dplyr)

y <- iris %>% 
  sample_frac(0.3) # Take a subset

y.mat <- y %>% 
  select(-Species) %>% ## Remove identifier
  data.matrix() ## Convert to matrix

heatmap.2(y.mat, main="iris", trace="none", 
          margins = c(10,12), cexRow=0.5,
          labRow = y$Species)

## Alternatively set the rownames of your data.matrix
y.mat2 <- y.mat
row.names(y.mat2) <- y$Species
heatmap.2(y.mat2, main="iris", trace="none", 
          margins = c(10,12), cexRow=0.5)

3 个答案:

答案 0 :(得分:3)

您需要添加点击事件:

select materials.id, 
        material_lists.name, material_lists.cost, 
        colors.code, colors.hex, colors.name,
        materials.color_cost, materials.estimation, materials.remarks
    from materials 
    inner join  
    material_lists on materials.material_id = material_lists.id 
    inner join
    colors on colors.id = materials.color_id 
    where carpet_id = '2'

在组件中:

 <button class="dropdown-item" (click)="changeAction(obj)">

答案 1 :(得分:1)

我在 Angular 6 中以下列方式取得了成就,

在我的 .html 文件中,

<div class="row">
  <div class="col">
    <div ngbDropdown class="d-inline-block">
      <button
        class="btn btn-outline-primary"
        id="dropdownBasic1"
        ngbDropdownToggle
      >
        {{searchSelector}}
      </button>
      <div ngbDropdownMenu aria-labelledby="dropdownBasic1" >
        <button ngbDropdownItem (click)="ngDropDwonClick('Action 1')">
          Action - 1
        </button>
        <button ngbDropdownItem (click)="ngDropDwonClick('Action 2')">
           Action - 2
        </button>
        <button ngbDropdownItem (click)="ngDropDwonClick('Action 3')">
          Action -3
        </button>
      </div>
    </div>
  </div>

在我的 .ts 文件中,

searchSelector = "Deafult";

  ngDropDwonClick(value) {
    this.searchSelector = value;
  }

你可以在这里找到一个工作演示, https://stackblitz.com/edit/angular-w6ycdf-t4s2ut?file=src%2Fapp%2Fdropdown-basic.ts

答案 2 :(得分:0)

此程序运行时没有任何JavaScript后端代码。解决方案是基于角度模板变量。 在没有选择任何项目之前,将显示占位符文本“选择环境”。

<div ngbDropdown class="d-inline-block">
    <button class="btn btn-outline-primary" id="dropdown"
       ngbDropdownToggle>{{ selectedValue.value || "Select Environment" }}</button>
    <div ngbDropdownMenu aria-labelledby="dropdown" #selectedValue>
      <div *ngFor="let env of environments;" >
        <button ngbDropdownItem id="option" on-click="selectedValue.value=env">{{env}} 
        </button>
      </div>
    </div>
</div>