Ошибка гласила: «Рассмотрите возможность использования декоратора @Inject для указания токена инъекции». Как мне это сделать?
У меня есть этот код в angular, в котором ошибка предлагает использовать декоратор @inject, но я не знаю, как это сделать, потому что я новичок в Angular. Я также предоставил пример ошибки, которую я получил. Надеюсь, кто-нибудь мне поможет.
**navbar.component.ts**
import { Component, OnInit, ElementRef } from '@angular/core';
import { ROUTES } from '../sidebar/sidebar.component';
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { ServicesService } from '../services.service';
import { Router } from '@angular/router';
@Component({
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrls: ['./navbar.component.css']
})
export class NavbarComponent implements OnInit {
private listTitles: any[];
location: Location;
mobile_menu_visible: any = 0;
private toggleButton: any;
private sidebarVisible: boolean;
title = 'angulartoastr';
showModal: boolean;
submitted = false;
loginForm: FormGroup;
invalidLogin: boolean = false;
message: any;
constructor(location: Location,
private element: ElementRef,
private router: Router,
private formbuilder: FormBuilder,
private apiService: ServicesService // This is where error occurred
) {}
Это ошибка:
Error: src/app/components/navbar/navbar.component.ts:30:132 - error NG2003: No suitable injection token for parameter 'apiService' of class 'NavbarComponent'.
Consider using the @Inject decorator to specify an injection token.
30 constructor(location: Location, private element: ElementRef, private router: Router, private formbuilder: FormBuilder, public apiService: ServicesService) {
~~~~~~~~~~
src/app/components/navbar/navbar.component.ts:30:144
30 constructor(location: Location, private element: ElementRef, private router: Router, private formbuilder: FormBuilder, public apiService: ServicesService) {
~~~~~~~~~~~~~~~
This type does not have a value, so it cannot be used as injection token.