Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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 offsetHeight和scrollHeight比较仅在Angular指令中的setTimeout内工作_Javascript_Html_Angular_Dom_Angular2 Directives - Fatal编程技术网

Javascript offsetHeight和scrollHeight比较仅在Angular指令中的setTimeout内工作

Javascript offsetHeight和scrollHeight比较仅在Angular指令中的setTimeout内工作,javascript,html,angular,dom,angular2-directives,Javascript,Html,Angular,Dom,Angular2 Directives,我需要检查偏光是否低于角度指令中的滚动高度。问题是它的工作原理如下。我希望避免使用setTimeout。你能给我推荐一些解决办法吗?提前谢谢 @Directive({ selector: '[appEllipsisDirective]' }) export class EllipsisDirective implements AfterViewInit { constructor(private ref: ElementRef) { } ngAfterViewInit() {

我需要检查偏光是否低于角度指令中的滚动高度。问题是它的工作原理如下。我希望避免使用setTimeout。你能给我推荐一些解决办法吗?提前谢谢

@Directive({
  selector: '[appEllipsisDirective]'
})
export class EllipsisDirective implements AfterViewInit {

 constructor(private ref: ElementRef) {
 }

  ngAfterViewInit() {
    setTimeout(() => {
      if (this.ref.nativeElement.offsetHeight < this.ref.nativeElement.scrollHeight) {
        this.init.emit(true);
      }
    });
  }
}

```
@指令({
选择器:“[AppellipsDirective]”
})
导出类EllipsisDirective在ViewInit之后实现{
构造函数(私有引用:ElementRef){
}
ngAfterViewInit(){
设置超时(()=>{
if(this.ref.nativeElement.offsetHeight
我不太确定您是否想简单地使用.css实现。如果你定义了一些

.content
{
  display:flex;
  flex-wrap: nowrap;
  justify-content:space-between;
  align-items: flex-start;
  width:100%;
}
.line-clam
{
  display:block;
 overflow:hidden;
}
你可以有


知识是一种美德,是一种美德,是一种美德,是一种美德,是一种美德。。。。
{{更多?'more':'less'}
一
二
嗯,您可以在ngOnInit中添加对window.resize的订阅,以表示有角度,使

  ngOnInit()
  {
   fromEvent(window, 'resize').pipe(debounceTime(1000)).subscribe();
  }

您可以在

中看到,如果不添加
设置超时
,会发生什么情况?你能把这个行为添加到你的问题中吗?我想你需要一个滚动事件,添加HostListener with scroll事件,检测滚动高度以及内部的视线偏移,下面是图片中的一些示例。问题是当我在全尺寸dekstop屏幕上打开页面时,橙色的show more按钮不会出现在文本下,即使文本的高度大于主机的高度。以防我在响应视图中打开我的条件WOKR。