![](/img/trans.png)
[英]How do I refresh the page when a user is routed in Ionic 5 using Angular
[英]How to trigger animation when routed to the same page with different URL parameter using Angular in Ionic 5
当页面使用不同的 url 参数路由到自身时,我试图触发 animation 。
例如,对于post/1
url,animation 工作正常,但如果我路由到post/2
或post/3
,animation 不起作用。
我使用离子 Animation编写了 animation 并在每次路由参数更改时调用该方法。 有人可以帮忙吗?
这是我的代码的摘录
HTML
<ion-icon class="custom-icon" name="chevron-back-outline"></ion-icon>
TS
constructor(private animationController: AnimationController) {
this.route.params.subscribe((val) => {
this.animateIcon();
});
}
animateIcon() {
this.animationController
.create()
.addElement(document.querySelector('.custom-icon'))
.duration(1500)
.iterations(3)
.fromTo('transform', 'translateX(0px)', 'translateX(-80px)')
.fromTo('opacity', '1', '0')
.play();
}
尝试将调用 function 到 ionViewWillEnter()
constructor(private animationController: AnimationController) {
}
ionViewWillEnter(){
this.route.params.subscribe((val) => {
this.animateIcon();
});
}
animateIcon() {
this.animationController
.create()
.addElement(document.querySelector('.custom-icon'))
.duration(1500)
.iterations(3)
.fromTo('transform', 'translateX(0px)', 'translateX(-80px)')
.fromTo('opacity', '1', '0')
.play();
}
我自己已经弄清楚了。 我没有使用querySelector
捕获 class 名称,而是使用ElementRef
表示法使其工作。 现在,当我路由到任何/post
页面时,它一直都在工作。
HTML
<ion-icon #leftIcon class="custom-icon" name="chevron-back-outline"></ion-icon>
TS
@ViewChild('icon1', { read: ElementRef, static: false }) leftIcon: ElementRef;
constructor(private animationController: AnimationController) {
this.route.params.subscribe((val) => {
this.animateIcon();
});
}
animateIcon() {
this.animationController
.create()
.addElement(this.leftIcon.nativeElement)
.duration(1500)
.iterations(3)
.fromTo('transform', 'translateX(0px)', 'translateX(-80px)')
.fromTo('opacity', '1', '0')
.play();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.