0

I am trying to add pagination to my table by following this link:

https://ng-bootstrap.github.io/#/components/table/examples (under Pagination).

The problem is that I'm getting an error on map(product,i)..; this is the error:

  • Property 'map' does not exist on type 'typeof Product'.
  • Parameter 'product' implicitly has an 'any' type.
  • Parameter 'i' implicitly has an 'any' type.

Will you kindly help me? Thank you all.

import { Product } from '../product';
import { Observable, Subject } from "rxjs";
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import {map} from 'rxjs/operators';

import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms';

@Component({
  selector: 'app-product-list',
  templateUrl: './product-list.component.html',
  styleUrls: ['./product-list.component.css']
})
export class ProductListComponent implements OnInit {

  constructor(private productservice: ProductService, private fb: FormBuilder, private modalService: NgbModal) {} 

  productsArray: any[] = [];
  dtTrigger: Subject<any> = new Subject();

  products: Product[] = [];
  product: Product = new Product();
  productlist: any;
  page = 1;
  pageSize = 4;
  collectionSize = Product.length;


  ngOnInit() {
  this.productservice.getProductList().subscribe(data => {
      console.log(data)
      this.products = data;
      this.dtTrigger.next();
    })
    this.editProfileForm = this.fb.group({
      productcode: [''],
      name: ['']
     });

     this.refreshProduct();
  }

  refreshProduct() {
    this.products = Product
      .map((product: any, i: number) => ({id: i + 1, ...product}))
      .slice((this.page - 1) * this.pageSize, (this.page - 1) * this.pageSize + this.pageSize);
  }
  .
  .
  }

1 Answer 1

1

you probably meant to do the below:

  ngOnInit() {
      this.productservice.getProductList().subscribe(data => {
          this.products = data;
          this.dtTrigger.next();
          this.refreshProduct();
      })
      this.editProfileForm = this.fb.group({
          productcode: [''],
          name: ['']
      });
  }

  refreshProduct() {
      this.productsArray = this.products
          .map((product: any, i: number) => ({ id: i + 1, ...product }))
          .slice((this.page - 1) * this.pageSize, (this.page - 1) * this.pageSize + this.pageSize);
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.