I already tried these two methods -
ngAfterViewInit() or ngAfterContentInit()
Here is my code -
import { Component, OnInit } from '@angular/core';
import { HomepageService } from '../services/homepage.service';
declare var $: any;
@Component({
selector: 'app-detailpage',
templateUrl: './detailpage.component.html',
styleUrls: ['./detailpage.component.css']
})
export class DetailpageComponent implements OnInit {
public errorMessage;
public productdata;
public title;
public address;
public old_price;
public discount;
public provider;
public image;
public description;
public merchant;
public new_price;
constructor(protected HomepageService: HomepageService) {
}
ngOnInit() {
this.HomepageService.getdetail() .then(
data => {
//console.log(data);
// let topdeals = <any>data ;
this.productdata = <any>data;
this.title = this.productdata.title;
this.address = this.productdata.address;
this.old_price = this.productdata.old_price;
this.discount = this.productdata.discount;
this.provider = this.productdata.provider;
this.image = this.productdata.image;
this.description = this.productdata.description;
this.merchant = this.productdata.merchant;
this.new_price = this.productdata.new_price;
},
error => {
this.errorMessage = <any>error ;
//alert(this.errorMessage.message);
});
}
ngAfterViewInit() {
var owl = $('.gallery .owl-carousel');
owl.owlCarousel({
loop: true,
items: 1,
thumbs: true,
thumbImage: true,
thumbContainerClass: 'owl-thumbs',
thumbItemClass: 'owl-thumb-item'
});
}
}
In my html template i am passing image variable inside owl-carousel -
Problem is that my jquery code executed before even my angular 2 page rendered properly. I have face same issue with my other jquery scripts also. I do not know how to stop executing my custom jquery code before page completely rendered in angular 2.