0
私はNGルーティング用にui-routingを使用しています(各セクションは異なるです)。 一部のセクションでは、ngZoneで(waypoint.js - imakewebthings.com/waypoints/)を使用しています。実際のページの高さを得るには、すべての画像と動画(ページ内のすべてのビューで)を読み込む必要があります。それが可能かどうか、どうすればこのことができますか?角4すべての画像がロードされるのを待つ方法
addEventListener('load', ...)
のようなものは、いくつかのページ(それぞれに複数のセクション(ui-view)を持っている)があり、最初の開いているページのためだけに機能するため動作しません。
マイコード:
<section class="moving-car" id="moving-car" [ngClass]="{'is-active': isActive}">
<!-- content -->
</section>
TS:
import { Component, OnInit, AfterViewInit, OnDestroy, NgZone,
ChangeDetectorRef } from '@angular/core';
declare var Waypoint: any;
import 'waypoints/lib/noframework.waypoints.js';
@Component({
selector: 'app-avensis-moving-car',
templateUrl: './avensis-moving-car.component.html',
styleUrls: ['./avensis-moving-car.component.scss']
})
export class AvensisMovingCarComponent implements OnInit, OnDestroy, AterViewInit {
constructor(
private $zone: NgZone,
private ref: ChangeDetectorRef
) {}
private waypoint: any;
public isActive: boolean = false;
ngOnInit() {}
ngAfterViewInit(): void {
const activate =() => {
this.isActive = true;
this.ref.detectChanges();
};
this.$zone.runOutsideAngular(
() => {
/* this code below I want run after loaded all image in my
subpage (not only in this component) */
this.waypoint = new Waypoint({
element: document.getElementById('moving-car'),
handler: function (direction) {
activate();
this.destroy();
},
offset: '70%'
});
}
);
}
ngOnDestroy() {
this.waypoint.destroy();
}
}
AngularJSを使用していますか? –
いいえ、私は角度4を使用しています – Eutrepe
これを実現する1つの方法は、あなたのwaypoint.jsエンドポイントをサービスに追加し、そのサービスをngInit()関数で呼び出すことです。 ngInit()で、ページコンポーネントの高さと幅を設定するための変数を操作します。 –