我嘗試製作作爲JSON對象檢索的篩選準則列表。然而,在運行代碼後,我得到一個DI錯誤。完全不知道錯誤可能出現在哪裏?有人有想法嗎?我的DI錯誤在哪裏?
錯誤:
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_.throwOrNull (http://localhost:8080/vendor.bundle.js:74856:19) at ReflectiveInjector.getByKeyDefault (http://localhost:8080/vendor.bundle.js:74895:25) at ReflectiveInjector.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_.getByKeyDefault (http://localhost:8080/vendor.bundle.js:74892:24) at ReflectiveInjector.getByKey (http://localhost:8080/vendor.bundle.js:74827:25) at ReflectiveInjector.get (http://localhost:8080/vendor.bundle.js:74696:21
)
下面是代碼的摘錄:
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;
});
});
,這是模塊定義:
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 { }
有什麼錯誤? – Sajeetharan
除了錯誤,你應該提供你的模塊定義,因爲這可能是問題所在。 – Steveland83
(這是Angular,而不是angularjs--你應該改變你的標籤)。 – Steveland83