1
내 html은 http get 요청을 사용하여 도시 목록을 렌더링합니다. 나는 put 요청을 사용하여 목록을 업데이트 할 때 HTML을 다시 렌더링하고 싶습니다. 어떻게하면 좋을까요?각도 : http put 요청을 사용한 후 http get request로 html을 업데이트하는 방법은 무엇입니까?
HTML :
<div *ngFor="let city of cityList">
<h4>{{city}}</h4>
</div>
타이프 :
cityList: string[];
ngOnInit() {
this.getCities();
}
getCities() {
this.cityListService.getCitiesSaved().subscribe(
cities => {
this.cityList = cities;
}
);
}
서비스 : 각도에서
currentCityList: string[];
getCitiesSaved(): Observable<string[]> {
return this.http.get(this.url).map((data: Response) => {
this.currentCityList = data.json().cityAlerts;
return data.json().cityAlerts;
});
}
지금과 똑같은 방식으로 가져 가야하는 대신 .... 내 질문에 정확히 무엇인지 모르겠습니다. 어디서 붙어 있니? 귀하의 오류/문제는 무엇입니까? – Igor
'cityList' 배열의 내용을 변경하면 Angular는 HTML을 자동으로 업데이트합니다. PUT 후에 배열을 업데이트하면 설정됩니다. –
또한'Http'는'HttpClient'를 위해 더 이상 사용되지 않습니다. 대신 그 사용을 권합니다. – Igor