Angular - ошибка TS2339: свойство 'take' не существует для типа 'AngularFireObject <{}>' - PullRequest
0 голосов
/ 27 апреля 2019

Я пытался изменить форму продукта, и я получаю сообщение об ошибке, когда пытаюсь использовать свойство "take". Более конкретно, я получаю: «Свойство take не существует для типа 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() {
  }

}

1 Ответ

1 голос
/ 27 апреля 2019

Если ваш метод this.productService.get(id) возвращает Observable, вы должны окружить своих операторов функцией pipe ():

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