简体   繁体   English

我的DI错误在哪里?

[英]Where is my DI error?

I try to make a filtered list of guidelines that are retrieved as a JSON object. 我尝试制作一个作为JSON对象检索的准则的过滤列表。 However after running the code i get a DI error. 但是,运行代码后,我得到一个DI错误。 Totally don't know where the error might arise? 完全不知道错误可能发生在哪里? Does anybody have an idea? 有人有主意吗?

The error: 错误:

error_handler.js:54 EXCEPTION: Uncaught (in promise): Error: DI Error Error: DI Error at NoProviderError.ZoneAwareError ( http://localhost:8080/polyfills.bundle.js:3423:33 ) at NoProviderError.BaseError [as constructor] ( http://localhost:8080/vendor.bundle.js:27156:16 ) at NoProviderError.AbstractProviderError [as constructor] ( http://localhost:8080/vendor.bundle.js:55463:16 ) at new NoProviderError ( http://localhost:8080/vendor.bundle.js:55525:16 ) at ReflectiveInjector_. error_handler.js:54例外:未捕获(承诺):错误:DI错误错误:NoProviderError.ZoneAwareError( http:// localhost:8080 / polyfills.bundle.js:3423:33 )处的DI错误,位于NoProviderError.BaseError [as构造函数]( http:// localhost:8080 / vendor.bundle.js:27156:16 )在NoProviderError.AbstractProviderError [作为构造函数]( http:// localhost:8080 / vendor.bundle.js:55463:16 )在新ReflectiveInjector_上的NoProviderError( http:// localhost:8080 / vendor.bundle.js:55525:16 )。 throwOrNull ( http://localhost:8080/vendor.bundle.js:74856:19 ) at ReflectiveInjector . 在ReflectiveInjector处抛出throwOrNull( http:// localhost:8080 / vendor.bundle.js:74856:19 getByKeyDefault ( http://localhost:8080/vendor.bundle.js:74895:25 ) at ReflectiveInjector . 在ReflectiveInjector处的getByKeyDefault( http:// localhost:8080 / vendor.bundle.js:74895:25 getByKey ( http://localhost:8080/vendor.bundle.js:74827:25 ) at ReflectiveInjector .get ( http://localhost:8080/vendor.bundle.js:74696:21 ) at AppModuleInjector.NgModuleInjector.get ( http://localhost:8080/vendor.bundle.js:56399:52 ) at CompiledTemplate.proxyViewClass.AppView.injectorGet ( http://localhost:8080/vendor.bundle.js:75631:45 ) at CompiledTemplate.proxyViewClass.DebugAppView.injectorGet ( http://localhost:8080/vendor.bundle.js:76059:49 ) at ElementInjector.get ( http://localhost:8080/vendor.bundle.js:75135:27 ) at ReflectiveInjector_. 在ReflectiveInjector .get( http:// localhost:8080 / vendor.bundle.js:74696:21 )的getByKey( http:// localhost:8080 / vendor.bundle.js:74827:25 (在AppModuleInjector.NgModuleInjector.get( http:// localhost:8080 / vendor.bundle.js:56399:52 )位于CompiledTemplate.proxyViewClass.AppView.injectorGet( http:// localhost:8080 / vendor.bundle.js:75631:45 )位于CompiledTemplate.proxyViewClass。在ReflectiveInjector_处的ElementInjector.get( http:// localhost:8080 / vendor.bundle.js:75135:27 )上的DebugAppView.injectorGet( http:// localhost:8080 / vendor.bundle.js:76059:49 )。 getByKeyDefault ( http://localhost:8080/vendor.bundle.js:74892:24 ) at ReflectiveInjector . ReflectiveInjector的getByKeyDefault( http:// localhost:8080 / vendor.bundle.js:74892:24 getByKey ( http://localhost:8080/vendor.bundle.js:74827:25 ) at ReflectiveInjector .get ( http://localhost:8080/vendor.bundle.js:74696:21 ReflectiveInjector .get( http:// localhost:8080 / vendor.bundle.js:74696:21处的 getByKey( http:// localhost:8080 / vendor.bundle.js:74827:25

)

Here is an excerpt of the code: 以下是代码摘录:

import { Component, OnInit, ElementRef, Injectable } from '@angular/core';
import { FormControl, FormArray, FormGroup, FormBuilder, Validators } from '@angular/forms';
import { Recommendation, Question, PreReq, Topic } from '../recommendations/recommendation';

import { RecommendationService } from '../recommendations/recommendation.service';

@Component({
  selector: 'app-inputform',
  templateUrl: './inputform.component.html',
  styleUrls: ['./inputform.component.css']
})


export class InputformComponent implements OnInit{
  inputform: FormGroup;
  Recommendations: Recommendation[];
  Guidelines: string[] = [];
  Topics: string [] = [];
  Questions: string [] = [];
  public query = '';
  public filteredList = [];
  public elementRef;
  selectedIdx: number;

  constructor(private fb: FormBuilder, myElement: ElementRef, private RecommendationService: RecommendationService) {
    this.elementRef = myElement;
    this.selectedIdx = -1;
    this.createForm();
  }

  ngOnInit() {
  this.RecommendationService
        .getRecommendations()
        .then((Recommendations: Recommendation[]) => {
        this.Recommendations = Recommendations.map((Recommendation) => {
          let checker = 0;
          console.log(Recommendation.guideline);
          for (let i = 0; i < this.Guidelines.length; i++) {
            if (Recommendation.guideline == this.Guidelines[i]) {
               checker = 1;
            }
          }
          if (checker == 0) {
            this.Guidelines.push(Recommendation.guideline);
          }
          checker = 0;

          return Recommendation;
        });
      });

and this is the module definition: 这是模块定义:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { ReactiveFormsModule } from '@angular/forms';  // <-- #1 import module voor reactieve forms
import { AppComponent } from './app.component';
import { RecommendationDetailsComponent } from './recommendations/recommendation-details/recommendation-details.component';
import { RecommendationListComponent } from './recommendations/recommendation-list/recommendation-list.component';
import { RecommendationSearchComponent } from './recommendations/recommendation-details/recommendation-search';
import { AppRoutingModule } from './app-routing.module';
import { GuidelinepageComponent } from './guidelinepage/guidelinepage.component';
import { InputformComponent } from './inputform/inputform.component';

@NgModule({
  declarations: [
    AppComponent,
    RecommendationDetailsComponent,
    RecommendationListComponent,
    RecommendationSearchComponent,
    GuidelinepageComponent,
    InputformComponent,
  ],
  imports: [
    AppRoutingModule,
    BrowserModule,
    FormsModule,
    HttpModule,
    ReactiveFormsModule 
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Looks like you're not providing your RecommendationService 好像您没有提供RecommendationService

try modifying the providers section in your module code to: 尝试将模块代码中的providers部分修改为:

providers: [ RecommendationService ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM