实现的内容如何在角度6中显示更多而显示更少

时间:2018-11-19 09:50:43

标签: angular bootstrap-4 angular6

我们有6个内容分区。而且我们在每个div处使用字符限制。 我们使用了bootstrap 4 angular 6版本。

6 div some toggle div content opened and some closed 如何实现这种情况。

2 个答案:

答案 0 :(得分:2)

使用某些自定义CSS非常容易实现。试试看:

模板:

<div class="container" [class.show]="show">
    Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<button (click)="show = !show">{{ show ? 'Show less': 'Show More' }}</button>

CSS:

.container {
  font-size: 16px;
  line-height: 16px;
  height: 32px;
  overflow: hidden;
}

.show {
  overflow: visible;
  height: auto;
}

组件:

show = false;

这是您推荐的Sample StackBlitz

答案 1 :(得分:0)

您可以使用<ng-container>来创建其他html节点

<div class="container" [class.show]="show">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
  Curabitur a felis odio. Nam et feugiat purus. 
  Nunc non ex mi. Phasellus at arcu id tortor gravida pellentesque. 

  <ng-container *ngIf="showMore1">

  Duis enim justo, placerat non dui non, placerat semper est. 
  Ut pulvinar aliquet lectus vulputate rutrum. 
  Maecenas suscipit, sapien ut fermentum hendrerit, 
  nibh augue scelerisque felis, in fermentum elit augue sed odio. 
  ...

  </ng-container>
</div>

<button (click)="showMore1= !showMore1">show {{showMore1 ?'less':'more' }}</button>