Observable이 완료되면 간단한 콜백을 구현하려고합니다. 여기에 내 코드가 있습니다.
ngOnInit() {
this.propertyService
.getProperties()
.subscribe(
(data: ContentPropertyModel[]) => this.properties = data
);
this.status = 'active';
}
그러나 관찰 가능이 실행되기 전에 상태가 변경됩니다. 관찰 가능한 실행 후 this.status를 어떻게 변경할 수 있는지에 대한 아이디어가 있습니까?
Subscribe는 세 가지 인수 (OnNext 함수, 오류 함수, 완료된 함수)를받습니다.
각 항목이 수신 된 후에 코드를 실행하려면 첫 번째 함수 인수에 코드를 입력하십시오. 스트림 완료 후 실행하려면 마지막 함수 인수에 코드를 작성하십시오.
ngOnInit() {
this.propertyService
.getProperties()
.subscribe(
(data: ContentPropertyModel[]) => {
this.properties = data
},
(err) => console.log(err),
() => this.status = 'active'
);
}
이 링크 http://reactivex.io/documentation/observable.html을 참조하십시오 .
또한 onError () 및 Completed () 함수는 DOM 이벤트에 대해 작동하지 않습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다