Error loading @angular/common/http - angular 2 -


i trying implement service in angular 2.

service:

import { injectable } '@angular/core'; import { httpclient } '@angular/common/http'; import { observable } 'rxjs/observable'; import { browsermodule } '@angular/platform-browser';   @injectable() export class demoservice {   constructor(private http: httpclient          ) { }   getdata(): observable<string> {     const baseurl = 'http://localhost:54037/api/home'; //  part   come  config  file  in futer    // const url = '?resourceid=' + primaryid + '&showdate=' + selecteddate;     // http://localhost:55174/api/resource?resourceid=3&showdate=2017-06-06     return this.http       .get<string>(baseurl);   }  } 

component:

import { component, oninit } '@angular/core'; import { demoservice } './app.service'; import { browsermodule } '@angular/platform-browser';  @component({   selector: 'my-app',   template: `<h1>hello {{name}}</h1>`,  }) export class appcomponent implements oninit  {     constructor(private s: demoservice){}    name = 'angular 2';  ngoninit(){ console.log("inidialization completed");  }  } 

everything works fine create instance of service in constructor under component class, error @ console.

error loading http://localhost:3002/node_modules/@angular/common/bundles/common.umd.js/http "@angular/common/http" http://localhost:3002/app/app.service.js

if remove constructor part, output.

i need create instance of constructor , call service.

am doing wrong?

importing httpmodule in app.module below

import { httpmodule} '@angular/http' 

and

importing http in service below

import { http, response} '@angular/http' 

solved problem.


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -