Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/403.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用溢出省略号7创建“显示更多效果”_Javascript_Css_Angular_Typescript_Angular Material - Fatal编程技术网

Javascript 使用溢出省略号7创建“显示更多效果”

Javascript 使用溢出省略号7创建“显示更多效果”,javascript,css,angular,typescript,angular-material,Javascript,Css,Angular,Typescript,Angular Material,我试图显示一个字符串数组。我想设置使用省略号显示更多效果。我有以下代码 const student={}; student.name=['Student1','Student2','Student3','Student4','Student5','Student6']; <h5 class="studnames">Student List <strong>{{ student.name| slice:0:2 }}{{student.name.len

我试图显示一个字符串数组。我想设置使用省略号显示更多效果。我有以下代码

const student={};
 student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];

<h5 class="studnames">Student List
<strong>{{ student.name| slice:0:2 }}{{student.name.length > 2 ? '...': ''}}</strong>
</h5>
constudent={};
student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
学生名单
{{student.name | slice:0:2}{{student.name.length>2?'…':''}
  • 只需在行中显示两个名称(Student1、Student2,…)
  • 单击3个点时,将剩余名称显示为一个小弹出窗口(单击/鼠标悬停)

  • 如何做到这一点。有什么想法吗?

    我建议你做如下事情:

    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
    <span *ngIf="student.name.length > 2" (click)="showStudentsPopUp()" (mouseover)="showStudentsPopUp()"> ... </span>
    </strong>
    </h5>
    
    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
      <ng-container *ngIf="student.name.length > 2">
        <span *ngTippy="config"> ... </span>
      </ng-container>
    </strong>
    </h5>
    
    constudent={};
    student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    学生名单
    {{student.name | slice:0:2}
    ... 
    
    
    然后,您可以简单地以任何方式实现showStudentsPopUp


    对于更实际的解决方案,我建议查看一些库,我过去使用过,它非常好,您可以这样做:

    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
    <span *ngIf="student.name.length > 2" (click)="showStudentsPopUp()" (mouseover)="showStudentsPopUp()"> ... </span>
    </strong>
    </h5>
    
    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
      <ng-container *ngIf="student.name.length > 2">
        <span *ngTippy="config"> ... </span>
      </ng-container>
    </strong>
    </h5>
    
    constudent={};
    student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    学生名单
    {{student.name | slice:0:2}
    ... 
    
    
    这将在鼠标悬停/点击时显示一个很好的工具提示,您可以在其中填充学生


    在这里,您可以找到Angular的tippy.js:

    我建议您执行以下操作:

    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
    <span *ngIf="student.name.length > 2" (click)="showStudentsPopUp()" (mouseover)="showStudentsPopUp()"> ... </span>
    </strong>
    </h5>
    
    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
      <ng-container *ngIf="student.name.length > 2">
        <span *ngTippy="config"> ... </span>
      </ng-container>
    </strong>
    </h5>
    
    constudent={};
    student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    学生名单
    {{student.name | slice:0:2}
    ... 
    
    
    然后,您可以简单地以任何方式实现showStudentsPopUp


    对于更实际的解决方案,我建议查看一些库,我过去使用过,它非常好,您可以这样做:

    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
    <span *ngIf="student.name.length > 2" (click)="showStudentsPopUp()" (mouseover)="showStudentsPopUp()"> ... </span>
    </strong>
    </h5>
    
    const student={};
     student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    
    <h5 class="studnames">Student List
    <strong>{{ student.name| slice:0:2 }}
      <ng-container *ngIf="student.name.length > 2">
        <span *ngTippy="config"> ... </span>
      </ng-container>
    </strong>
    </h5>
    
    constudent={};
    student.name=['Student1','Student2','Student3','Student4','Student5','Student6'];
    学生名单
    {{student.name | slice:0:2}
    ... 
    
    
    这将在鼠标悬停/点击时显示一个很好的工具提示,您可以在其中填充学生


    在这里,您可以找到Angular的tippy.js:

    无法使用
    文本溢出:省略号来实现这一点?我添加此作为评论,因为我不是100%确定您想要做什么,我认为一个可行的stackblitz和一个更清晰的解释将非常有用:)问题更新OK谢谢:)无法通过
    文本溢出:省略号实现这一点?我加上这个作为一个评论,因为我不是100%确定你想做什么,我认为一个可行的stackblitz和一个更清晰的解释将真的很有帮助:)问题更新OK谢谢:)