我构建了一个看起来像
的下拉组件<my-drop-down>
<my-drop-down-element>First</my-drop-down-element>
<my-drop-down-element>Second</my-drop-down-element>
</my-drop-down>
为了完成这项工作,DropDownComponent中有一个@ContentChildren(DropDownElementComponent)
。到目前为止,这是完美的工作,但现在我有一个奇怪的要求:
我需要将下拉组件包装在另一个组件中,以处理其他一些东西。我试过的是:
wrapper.component.html:
<my-drop-down>
<ng-content></ng-content>
</my-drop-down>
app.component.html
<my-wrapper>
<my-drop-down-element>First</my-drop-down-element>
<my-drop-down-element>Second</my-drop-down-element>
</my-wrapper>
但遗憾的是,DropDownComponent中没有任何内容子项,如果我这样处理的话。我也试过@ContentChildren(DropDownElementComponent, {descendants: true})
有没有办法通过上面示例中的其他ng-content传递conten孩子?
答案 0 :(得分:1)
如果你想包裹df <- data.frame(a = c("A","A","A","A","B","B","C","C","C","D","D"),
b=c(1,2,3,4,1,2,1,2,3,1,2),
c=c(1345,645,75,8,95,678,598,95,75,4,53),stringsAsFactors = F)
library(dplyr)
df <- tbl_df(df)
df %>% group_by(a)%>%
mutate(d = ifelse(b == max(b),c[which(b == max(b))],0))
# A tibble: 11 x 4
# Groups: a [4]
a b c d
<chr> <dbl> <dbl> <dbl>
1 A 1 1345 0
2 A 2 645 0
3 A 3 75 0
4 A 4 8 8
5 B 1 95 0
6 B 2 678 678
7 C 1 598 0
8 C 2 95 0
9 C 3 75 75
10 D 1 4 0
11 D 2 53 53
,你可以这样做:
drop-down
<强> Demo 强>