назначение ответов сервера (Angular) - PullRequest
0 голосов
/ 03 марта 2019

Я отправляю содержимое константы «Галереи» в API с помощью «exportGalleries ()», но не знаю, как изменить отображение ответа сервера вместо локального содержимого в компоненте «gallery.component»

Я буду готов к любой помощи

gallery.component

@Component({
  selector: 'app-gallery',
  templateUrl: './gallery.component.html',
  styleUrls: ['./gallery.component.scss']
})
export class GalleryComponent implements OnInit {

  private galleryId: string;
  private gallery: IGallery;



  constructor(private route: ActivatedRoute) { }

  ngOnInit() {
    this.galleryId = this.route.snapshot.paramMap.get('galleryId');
    this.gallery = Galleries.find((item: IGallery) => item.galleryId === this.galleryId);
    console.log("GALL");
    console.log(this.gallery);
  }

}

  constructor(private http: HttpClient) {
    this.title='Galeria';
    this.description='Wakacje';

    this.galleries = [];

    this.http.get('http://project.usagi.pl/gallery',
    this.httpOptions).toPromise().then((response: IGallery[]) => {
        console.log(response);
      this.galleries = response;
      });
    this.searchValue ='';
  }

  ngOnInit() {
  }

  setSearchValue($event) {
    console.log($event);
    this.searchValue=$event;
  }

  exportGalleries() {
    Galleries.forEach((gallery: IGallery) => {
      delete(gallery.galleryId);
      this.http.post('http://project.usagi.pl/gallery', gallery,
        this.httpOptions).toPromise().then((response: IGallery) => {
        console.log('success', response);
        this.galleries.push(response);
      }, (errResponse) => {
        console.log('error', errResponse);
      });
    });
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...