47063: truncation option with shave library

This commit is contained in:
Lotte Hofstede
2017-12-19 11:54:20 +01:00
parent d7c2b09697
commit 970b1f6b74
7 changed files with 46 additions and 25 deletions

View File

@@ -1,10 +1,7 @@
import {
AfterViewChecked,
AfterViewInit, Component, ElementRef, Inject, Input,
ChangeDetectorRef, Component, ElementRef, Inject, Input,
OnInit
} from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { NativeWindowRef, NativeWindowService } from '../window.service';
@Component({
@@ -13,20 +10,19 @@ import { NativeWindowRef, NativeWindowService } from '../window.service';
})
export class TruncatableComponent implements OnInit {
@Input() lines: Observable<number>;
@Input() lines: number;
@Input() innerHTML;
@Input() height: Observable<number>;
height;
styles: any;
public constructor(private elementRef:ElementRef, @Inject(NativeWindowService) private _window: NativeWindowRef) { }
public constructor(private elementRef: ElementRef, @Inject(NativeWindowService) private _window: NativeWindowRef, private changeDetectorRef: ChangeDetectorRef) {
}
ngOnInit(): void {
const lineHeight = this._window.nativeWindow.getComputedStyle(this.elementRef.nativeElement).lineHeight.replace('px', '');
this.styles = this._window.nativeWindow.getComputedStyle(this.elementRef.nativeElement);
this.height = this.lines.map((lines) => (lines * lineHeight)).startWith(0);
this.print(this.styles);
}
print(styles) {
console.log(styles);
this.styles = this._window.nativeWindow.getComputedStyle(this.elementRef.nativeElement);
setTimeout(() => {
this.height = this.styles.lineHeight.replace('px', '') * this.lines;
this.changeDetectorRef.detectChanges();
}, 0);
}
}