0
私は、コンポーネント内のfolowing方法があります:サービスでなぜ「未定義」のIDがangular2で送信された後に変更されたのですか?
onSubmit() {
this.isLoading = true;
const successCallback = (result) => {
this.isLoading = false;
if (result) {
this.notificationId = result.Id;
}
this.router.navigate(['../' + this.notificationId], { relativeTo: this.route });
};
if (this.isNew) {
this.dataService.create(this.model).then(successCallback);
} else {
this.dataService.update(this.model).then(successCallback);
}
}
ngOnInit(): void {
this.isLoading = true;
this.notificationId = parseInt(this.route.snapshot.params['notificationid'], 10);
this.projectId = parseInt(this.route.snapshot.params['projectid'], 10);
let loadTask: Promise<NotificationOfParticipationViewModel>;
if (this.notificationId == 0) {
loadTask = Promise.resolve(new NotificationOfParticipationViewModel());
} else {
loadTask = this.dataService.getById(this.notificationId);
}
loadTask.then(result => {
this.model = Object.assign(new NotificationOfParticipationViewModel(), result);
this.isLoading = false;
});
}
を:
update(notification: NotificationOfParticipationViewModel): Promise<any> {
return this.baseService.put(this.apiUrl, notification);
}
create(signatory: NotificationOfParticipationViewModel): Promise<NotificationOfParticipationViewModel> {
return this.baseService.post(this.apiUrl, signatory);
}
Serverのいくつかの計算は、後に提出ありません。 26
がundefined
に変更し、なぜ私は、理解していない
http://localhost:55077/projects/2/notificationsofparticipation/undefined
:?
前URLは次のようになり提出:
http://localhost:55077/projects/2/notificationsofparticipation/26
しかし、後のURLは次のようになり提出
あなたはコンポーネントクラスの他の場所で 'notificationId'を初期化しましたか?いいえの場合は、 'result'がプロパティ' id'を持っていることを確認します。それ以外の場合、if文の次の行に 'notificationId'が定義されません。 – Ashot
サーバーコードを投稿できますか? –