nobanor
nobanor

Reputation: 1

Angular - error TS2339: Property 'take' does not exist on type 'AngularFireObject<{}>'

I was trying to edit a product form and I am getting an error when I try to use the property "take". More specifically I get: "Property 'take' does not exist on type 'AngularFireObject<{}>'."

import { Component, OnInit } from '@angular/core';
import { CategoryService } from 'src/app/category.service';
import { ProductService } from 'src/app/product.service';
import { Router, ActivatedRoute } from '@angular/router';
import 'rxjs/add/operator/take';

@Component({
  selector: 'app-product-form',
  templateUrl: './product-form.component.html',
  styleUrls: ['./product-form.component.css']
})
export class ProductFormComponent implements OnInit {
  categories$;
  product = {};
  //productService: any;

  constructor(
    private router: Router,
    private route: ActivatedRoute,
    //private categoryService: CategoryService, 
    private productService: ProductService) { 
    //this.categories$ = categoryService.getCategories()


    let id = this.route.snapshot.paramMap.get('id');
    if (id) this.productService.get(id).take(1).subscribe(p => this.product = p);
    //if (id) this.productService.get(id).valueChanges().subscribe(p => this.product = p);
  }

  save(product){
    this.productService.create(product);
    this.router.navigate(['admin/products']);
    //console.log(product);
  }
  ngOnInit() {
  }

}

Upvotes: 0

Views: 559

Answers (1)

MichelDelpech
MichelDelpech

Reputation: 863

If your this.productService.get(id) method returns an Observable, you have to surround your operators with the pipe() function :

this.productService.get(id).pipe(take(1)).subscribe(p => this.product = p);

Upvotes: 1

Related Questions