Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export class Index implements onInit{
- constructor (private http:Http){
- this.products : Observable<array>;
- this.page : Observable<array>;
- this.currentPage : Observable<number>;
- this.play = true;
- }
- ngOnInit() {
- this.currentPage = 0;
- this.getProducts();
- }
- getProducts(){
- var data = {"designer":"Leonardo"}
- var headers = new Headers();
- headers.append('Content-Type', 'application/json');
- this.http.post('/getProducts/', JSON.stringify(data), {
- headers: headers
- })
- .map(res => res.json())
- .subscribe(
- data => {
- this.devidePages(data);
- },
- err => console.log(err),
- () => console.log('Post Submited')
- );
- }
- devidePages(allproducts) {
- len = allproducts.length;
- var nrpages
- if ( Math.round(len/3) > parseInt(len / 3) ) {
- nrpages = Math.round(len/3) - 1;
- }
- else {
- nrpages = Math.round(len/3);
- }
- var j = -1;
- var page = [];
- for (i in allproducts) {
- var element = allproducts[i];
- if (i%3 == 0) {
- j++;
- page[j] = [];
- page[j].push(element);
- }
- else {
- page[j].push(element);
- }
- }
- this.products.subscribe(page[this.currentPage]);
- this.page = page;
- this.startInterval(page,nrpages);
- }
- startInterval(page,nrpages) {
- console.log(this.products)
- setInterval(function() {
- if (this.currentPage < nrpages) {
- this.products.subscribe(page[this.currentPage]);
- this.currentPage++;
- } else {
- this.currentPage = 0;
- this.products.subscribe(page[this.currentPage]);
- // timer = $timeout(function() {
- // this.products = [];
- // }, 2500);
- },6000)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement