]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-main/angular/auto-colspan.directive.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / angular / auto-colspan.directive.ts
1 import { AfterViewInit, Directive, ElementRef, Renderer2 } from '@angular/core'
2
3 @Directive({
4 selector: '[myAutoColspan]'
5 })
6 export class AutoColspanDirective implements AfterViewInit {
7
8 constructor (
9 private host: ElementRef,
10 private renderer: Renderer2
11 ) { }
12
13 ngAfterViewInit () {
14 const el = this.host.nativeElement as HTMLElement
15 const table = el.closest('table')
16 if (!table) throw new Error('table element not found')
17
18 const th = table.querySelectorAll('th')
19
20 this.renderer.setAttribute(el, 'colspan', th.length + '')
21 }
22 }