简体   繁体   English

如何将表单值发送到节点/快递到搜索数据库?

[英]How to send form value to node/express to search database?

I've got a pre populated form with gps coordinates and I am trying to search a database.我有一个带有 gps 坐标的预填充表格,我正在尝试搜索数据库。




<form>

<mat-toolbar  color="primary">

  <mat-toolbar-row style="justify-content: center;" id="test">  Yonder   </mat-toolbar-row>
 <br>


  <mat-toolbar-row style="justify-content: center;">  <input id="geoSearch" type="text" value="{{coords}}">  </mat-toolbar-row>
  <mat-toolbar-row style="justify-content: center;">    <button type="submit" class="subMitButton" id="location-button" mat-raised-button onclick="window.location.reload();" color="accent"> Locate </button>   </mat-toolbar-row>


</mat-toolbar>
<br>


</form>



and my backend code和我的后端代码


app.get('/api/animals',(req, res, next) => {

Animal.find({})
.then(documents => {
  res.status(200).json({
    message: 'success',
    animals: documents
  });
});



How can I send the data from the form to be used in the find query?如何从表单发送数据以用于查找查询?

Thanks!谢谢!

Use HttpClient to make the request to your endpoint.使用 HttpClient 向您的端点发出请求。 In this case you could have something like:在这种情况下,您可能会遇到以下情况:

 public response: any; constructor(private readonly http: HttpClient) {} public makeRequest(): void { this.http.get('XXXXXXXXX/api/animals').subscribe((response) => { this.response = response; // console.log(response) }) }

Where XXXXXXXXXXXX is your api base url (probably something like http://localhost:3000)其中 XXXXXXXXXXXX 是您的 api 基础 url (可能类似于 http://localhost:3000)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM