I am facing an issue while trying to inject a service into my component, resulting in the following error:
https://i.stack.imgur.com/zA3QB.png
news.component.ts
import { Component,OnInit } from '@angular/core';
import { NewsService } from './index';
declare var jQuery:any;
@Component({
moduleId: module.id,
selector: 'news-selector-comp',
templateUrl:'news.html'
})
export class NewsSelectorComponent implements OnInit {
isLoading = true;
isError = false;
News:any;
constructor(public newsService:NewsService) { }
}
news.module.ts
https://i.stack.imgur.com/YeIAJ.png
news.service.ts
import {Http, Headers} from '@angular/http';
import { Injectable } from '@angular/core';
import { News, NewsImp } from './news';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable()
export class NewsService {
_url = '<%= SYSTEM_URL%>/news';
token = window.localStorage.getItem('token');
user_id = window.localStorage.getItem('user_id');
constructor(private _http:Http) {
}
getNews() : Observable<NewsImp[]> {
return this._http.get('https://jsonplaceholder.typicode.com/posts').map(res => res.json());
}
postNews() : Observable<News[]> {
var headers = new Headers();
headers.append('Content-Type', 'application/json');
var news = {
user_id: this.user_id,
token : this.token
};
return this._http.post(this._url, JSON.stringify(news), {headers:headers}).map( res => res.json().data);
}
}