Napisałem sobie prostą apkę w stylu Trelo i dopóki korzystało z InMemoryWebApiModule wszystko działało ale postanowiłem to rozbudować i wystawiłem sobie kontroler napisany w Javie. I mam problem ponieważ nie potrafię go skonsumować. Macie może jakiś przykład jak konsumować API po http?
0
1
Przykład:
import { Component } from '@angular/core';
import { UsersListService } from '../../services/backend.service';
@Component({
selector: 'userslist',
styleUrls: ['./users-list.component.css'],
templateUrl: './users-list.component.html',
providers: [UsersListService]
})
export class UsersListComponent {
usernames: Array<string> = [];
constructor(private usersListService: UsersListService) {
usersListService.get().subscribe((res) => {
this.usernames = res.usernames;
});
}
}
@Injectable()
export class UsersListService {
constructor(private http: Http) { }
get() {
return this.http.get(API_URL + '/users').map(res => res.json());
}
}
0
Dzięki za pomoc, siadłem rano i wszystko działa. Chyba wczoraj miałem jakieś zmęczenie materiału :)