Home > database >  No suitable injection token for parameter 'functions' of class 'TodosComponent'
No suitable injection token for parameter 'functions' of class 'TodosComponent'

Time:03-21

I am using 'firebase' instead of '@angular/fire' and got an error saying No suitable injection token for parameter 'functions' of class 'TodosComponent'.

Code written in todos.component.ts

import { Component, OnDestroy, OnInit } from '@angular/core';
import { TodosService } from '../todos.service';
import { Todo } from './Todo';
import * as functions from 'firebase/functions';

declare var StripeCheckout: StripeCheckoutStatic;

@Component({
  selector: 'app-todos',
  templateUrl: './todos.component.html',
  styleUrls: ['./todos.component.scss']
})
export class TodosComponent implements OnInit, OnDestroy {

  todos!: Todo[];
  localItem: string | null;
  completedTodos: number = 0;
  date: string = new Date().toUTCString();

  constructor(private functions: functions.Functions) {
      ..........
  }

  ......

}

I am having a problem in private functions: functions.Functions.

CodePudding user response:

As you imported directly from 'firebase/functions', you don't need to inject in the constructor.

You can directly use the functions.

Remove private functions: functions.Functions from constructor.

Use the functions directly. No need to use this.functions

for example,

functions.firestore.document('/messages/{documentId}')
  • Related