I am able to get data using http (in a same component ) .But I am not getting data using service.can we call service method and grt data from server and display on component ? I try to make service and try to get data from server .But I am not able to know how to use this service ? http://plnkr.co/edit/hfhY6EdLVNOLP6d4QsWP?p=preview
import {Component, Injectable,Input,Output,EventEmitter} from 'angular2/core'
import {Http, HTTP_PROVIDERS} from 'angular2/http';
import 'rxjs/add/operator/map';
// Name Service
export interface myData {
name:Array;
}
@Injectable()
export class SharedService {
sharingData: myData=[{name:"nyks"}];
constructor(private http:Http) {
}
getData:Array()
{
this.sharingData.name=this.http.get('data.json')
.map(res => res.json());
return this.sharingData.name;
}
}