注入外部Angular服务时出现VSCode错误

时间:2017-10-14 11:17:08

标签: angular typescript visual-studio-code

当在注入外部服务时将鼠标悬停在VSCode中的@Component上时出现以下错误:[Angular] Can't resolve all parameters for AppComponent in /angular/nx/string-utils/apps/strings-test/src/app/app.component.ts: (?).但是如果我运行应用程序,一切正常。关于如何摆脱这个错误的任何建议?

这些是相关文件:

app.component.ts

import { Component, OnInit } from '@angular/core';
import { StringsService } from '@string-utils/strings-module/src/strings.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  constructor(private stringsService: StringsService) {}

  ngOnInit() {
    console.log(this.stringsService.toUpperCase('Marius'));
  }
}

app.module.ts

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { BrowserModule } from '@angular/platform-browser';
import { NxModule } from '@nrwl/nx';
import { StringsModuleModule } from '@string-utils/strings-module';
import { StringsService } from '@string-utils/strings-module/src/strings.service';

@NgModule({
  imports: [BrowserModule, NxModule.forRoot(), StringsModuleModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule { }

strings-module.module.ts

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { StringsService } from '@string-utils/strings-module/src/strings.service';

@NgModule({
  imports: [CommonModule],
  providers: [StringsService]
})
export class StringsModuleModule { }

0 个答案:

没有答案