0
サービスレイヤからコンポーネントにjsonを渡してから、関数を順番に呼び出すのに苦労しています。http投稿の角5戻りオブジェクト
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
です。どのように私はこれを修正することができます/私は間違って何ですか?
EDIT:コンポーネントのトップは、次のとおりです。
@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