[英]How to use Flip jQuery plugin in angular 4
I had a component that takes use of jQuery and Flip plugin for this one, the main problem is when i try to use it in ngAfterViewInit
it simply does not work, but also didn't get any error from log, is there maybe a step I'm forgetting to do so i can take use of flip plugin ? 我有一个组件需要为此使用jQuery和Flip插件,主要问题是当我尝试在ngAfterViewInit
使用它时,它根本无法正常工作,但也没有从日志中获取任何错误,也许有一个步骤我忘记这样做了,可以使用翻盖插件了吗?
Here is my code at the moment, hope you can help me guys and thanks for your time 现在这是我的代码,希望您能对我有所帮助,并感谢您的宝贵时间
import { Component, OnInit ,AfterViewInit} from '@angular/core';
import {ApiBackEndService} from '../api-back-end.service';
import { DatePipe } from '@angular/common';
import * as moment from 'moment';
declare var $ : any;
declare var flip : any;
@Component({
selector: 'app-booking',
templateUrl: './booking.component.html',
styleUrls: ['./booking.component.css']
})
export class BookingComponent implements OnInit , AfterViewInit{
...
constructor(private api:ApiBackEndService) { }
ngAfterViewInit(){
$(".flip").flip({
axis: 'y',
trigger: 'hover'
});
}
ngOnInit() {
this.api.loadRooms().subscribe(data=>{
this.rooms= data.rooms;
});
}
...
}
jQuery Version 3.* jQuery版本3. *
It seem since i'm using observables to fill the data of the ones that are into a .flip
class , something happened that it takes a few seconds to render the data, and the actually works, by now what i do it's setTimeOut
1 second and it works perfect, i'm looking for a better solution, any updates, i'll post it here 似乎因为我正在使用可观察对象将那些数据填充到.flip
类中,所以发生了一些事情,即渲染数据需要花费几秒钟,并且实际上是.flip
,现在我要做的是setTimeOut
1秒它工作完美,我正在寻找更好的解决方案,任何更新,我都会在此处发布
this.api.loadRooms().subscribe(data=>{
this.rooms= data.rooms;
this.enableAnimations();
});
enableAnimations(){
setTimeout(()=>{ $(".flip").flip({
axis: 'y',
trigger: 'hover'
}); }, 1000);
}
with this implementation, it works fine, i know it may be a better way to avoid timeout 通过这种实现,它可以正常工作,我知道这可能是避免超时的更好方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.