【发布时间】:2020-04-10 02:34:58
【问题描述】:
我想在我的 Angular 应用程序中构建一个评论部分。这些 cmets 应该存储在数据库中,所以我想将数据从 Angular 转发到 Node.js,然后可以将其传递到数据库。所以我在 detail.component.html 中为 cmets 创建了一个输入字段。当用户点击回车时,评论被保存。
<input #box (keyup.enter)="update(box.value)">
<p>{{value}}</p>
在 detail.component.ts 我将注释保存在一个变量中:
public value: any= []
update(comment: any) { this.value = comment; }
//code
this.dataService.addComment().subscribe(comment => this.value = comment)
这是第一个问题 - 我如何获得对 data.service.ts 的评论?
//code
addComment() {}
然后是实际的问题:如何在 node.js 应用程序中将此评论转发到 server.js?
我对 Angular 很陌生,所以我对如何实现这一点一无所知。我发现这个问题How to pass form data from angular to nodejssamewhat 很有用,但无法将其应用于我的用例。那么如何将数据从 Angular 传输到 Node.js?
【问题讨论】:
-
你的post api是在服务器端(nodejs)实现的吗?
-
@SiddharthPal - 是的,API 是由 server.js (nodejs) 创建的
标签: javascript node.js angular typescript