Сервис:
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs';
import { User } from './user';
@Injectable()
export class UserService{
constructor(private _httpService: Http){}
getAllUsers(){
return this._httpService.get("http://localhost:7777/webapp/user")
}
private handleError(error: Response){
return Observable.throw(error);
}
}
компонент:
import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {User} from './user';
import { UserService } from './user.service';
@Component({
selector: 'app-user',
templateUrl: './user.component.html',
styleUrls: ['./user.component.css']
})
export class UserComponent implements OnInit{
users: User[];
constructor(private _userService: UserService){}
ngOnInit(): void {
this.getUsers();
}
getUsers(): void{
this._userService.getAllUsers().subscribe(users => console.log(users), error => console.error(error));
}
}
спасибо большое за подсказку, теперь проект компилируется!!
однако после компиляции выдает ошибку:
Цитата:
|
ERROR in The target entry-point "@angular/http" has missing dependencies:
- @angular/core
- @angular/platform-browser
|