서비스 계층에서 구성 요소로 json을 전달한 다음 순차적으로 함수를 호출하는 데 어려움을 겪고 있습니다.http post에서 Angular 5 return 객체
users.service.ts
addUser(user: User) {
return this.http.post('http://localhost:8080/user/create', user).map(res => res.json());
}
다음 구성 요소 계층 : 여기에 이미 성취 한 것입니다
async onSubmit(model) {
await new Promise(resolve => {
setTimeout(() => {
this.submitted = true;
this.usersService.addUser(model).subscribe(data => this.savedModel = data);
resolve();
}, 500);
});
this.sendNotification();
}
@Output() notifyParent: EventEmitter<any> = new EventEmitter();
sendNotification() {
this.notifyParent.emit(JSON.stringify(this.savedModel));
}
savedModel
이 undefined
입니다. 이 문제를 어떻게 해결할 수 있습니까?/내가 뭘 잘못하고 있니?
편집 : 구성 요소의 상단은 다음과 같습니다 addUser
긴 500 초 복용 할 수있다처럼
@Component({
selector: 'app-user-form',
templateUrl: './user-form.component.html',
styleUrls: ['./user-form.component.css']
})
export class UserFormComponent implements OnInit {
groups: Group[];
model: User;
savedModel;
구성 요소에'savedModel'을 (를) 선언 했습니까? – cyberpirate92
부모 구성 요소의 모습 (자식 태그 및 이와 관련된 TS 코드) – Alex