I created a model class for movies in my project, which contains the following
export class Movie {
title:string;
overview:string;
id:string;
seasons:any[];
constructor(obj: any) {
this.id = obj.id;
this.overview = obj.overview;
this.title = obj.title;
}
}
I also made a service that forces all http calls to retrieve data from the api.
import { Injectable } from '@angular/core';
import { Headers, Http } from '@angular/http';
import 'rxjs/Rx';
import {Movie} from './movie/model';
@Injectable()
export class ApiService {
constructor(private http: Http) {}
getMovie(id):{
let url = this.Api_Url + '/movies/' + id + "?extended=full,images";
return this.http.get(url, { headers: this.headers })
.map(d => d.json())
.map(d => new Movie(d))
.toPromise()
}
getActors(){...}
Everything works fine, I provide one instance of the api service in my bootstrap, and I can use it in each component to get the movie. Although I would like to have this instance of the api service in my class, but I don't know how to tell angular to provide it. This is what I want and what I tried.
import {ApiService} from "../api.service";
export class Movie {
title:string;
overview:string;
id:string;
seasons:any[];
constructor(obj: any, private api: ApiService) {}
getActors(): {
this.api.getActors()
}
}
@Inject(api) new, , http. , angular api , , es6? -? angular 1, , .