22/11/2017 Development / angular

@Injectable()

export class ColaboradorService {

constructor(private http: Http) { }

getColaboradores(filters): Observable<any[]> {

return this.http.get('https://odete-app.herokuapp.com/colaboradores', filters)

.map(response => response.json())

.map((messages: Object[]) => {

return messages.map(message => message);

});

}

}

My component

import { ColaboradorService } from '../colaborador.service';

export class MainComponent implements OnInit {

data: Array<any> = [];

constructor(private service: ColaboradorService) {}

}

ngOnInit() {

this.service.getColaboradores(this.filters).subscribe(colaborades => this.data = colaborades);

}

Easy!