一个用于NativeElement:ElementRef`的Angular NPM包[像jQuery]?

时间:2018-09-07 01:33:49

标签: angular typescript dom

我很想将nativeElement中的以下ngAfterViewInit处理重构为静态方法的Typescript类:

export class AnimationBuilderComponent implements AfterViewInit {
    @ViewChild('photos') photosContainer: ElementRef;

    constructor(private animationBuilder: AnimationBuilder) {}

    ngAfterViewInit(): void {
        const div = this.photosContainer.nativeElement as HTMLDivElement;
        if (!div) {
            console.warn('the expected div element is not here');
            return;
        }
        const children = Array.from(div.children);
        if (!children) {
            console.warn('the expected div element children are not here');
            return;
        }
        if (!children.length) {
            console.warn(
                'the expected number of div element children is not here'
            );
            return;
        }
        children.forEach(el => {
            if (el.nodeName !== 'img'.toUpperCase()) {
                return;
            }
            console.log(el.clientWidth);
        });
    }

    animate(): void {
        console.log('animate!');
    }
}

在我匆匆忙忙执行此操作之前,是否已经有一个NPM软件包已执行此操作?实际上,我正在寻找一种能感知ElementRef的jQuery。

0 个答案:

没有答案