-1

我有这个 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.
4

0 回答 0