Angular 5 plunker, Can't resolve all parameters

236 views Asked by At

I can't get my Angular 5 plunker to work, it has the following error:

Error: Can't resolve all parameters for PersonService

I'm fairly sure it has something to do with the person service as everything else closely follows the application I've based this on.

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import { Http } from '@angular/http';

@Injectable()
export class PersonService {
    constructor(private _http: Http){}

    getPerson() {
        return this._http.get('./DummyAPI.html')
        .map(response => response.text());
    }
}

I'm trying to create it to demonstrate another problem I'm having.
Can someone please help me fix it?

2

There are 2 answers

2
William Moore On BEST ANSWER

Your app.module needs to import the 'HttpModule' and 'FormsModule' from '@angular/http' and '@angular/forms'. It should look something like this:

import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';
import { PersonService } from './person.service';

@NgModule({
  imports: [BrowserModule, HttpModule, FormsModule, ReactiveFormsModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
  providers: [PersonService]
})

export class AppModule { }

See working StackBlitz: https://stackblitz.com/edit/angular-h94pg7

0
Robin gupta On

This error generally comes when you have circular dependency of services.